From 4b5447c8287a1611e6238f0c552890c097653cb5 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Fri, 3 Jul 2026 14:37:32 +0330 Subject: [PATCH] Fix SSR 500 by proxying API requests to the Nuxt server port. Point axios proxy at the same process as serverMiddleware instead of an unused port, and allow MongoDB URI to be configured via env. Co-authored-by: Cursor --- nuxt.config.js | 6 ++++-- pages/_lang/index.vue | 3 ++- server/database.js | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nuxt.config.js b/nuxt.config.js index dcab424..6a960cb 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,5 +1,6 @@ const webpack = require('webpack'); -const serverport = 3711 +const nuxtPort = process.env.PORT || 3000 + export default { head: { title: 'OrisOxin', @@ -74,7 +75,8 @@ export default { proxy: true }, proxy: { - '/api': { target: `http://0.0.0.0:${serverport}` } + // SSR axios requests must hit the same Nuxt process that hosts serverMiddleware (/api). + '/api': { target: `http://127.0.0.1:${nuxtPort}` } }, router: { linkActiveClass: 'active-link', diff --git a/pages/_lang/index.vue b/pages/_lang/index.vue index 3e8b4c3..bbe958b 100644 --- a/pages/_lang/index.vue +++ b/pages/_lang/index.vue @@ -1030,7 +1030,8 @@ export default { blogPosts: blogPosts.data } } catch (e) { - error({ status: 500, message: 'there is a problem here' }) + console.error('Homepage asyncData failed:', e.message || e) + error({ statusCode: 500, message: 'there is a problem here' }) } } } diff --git a/server/database.js b/server/database.js index a9679ee..a142253 100644 --- a/server/database.js +++ b/server/database.js @@ -13,9 +13,9 @@ mongoose.plugin(schema => { }) }) -mongoose.connect('mongodb://root:e9a15xftSaqNgR1fNMSUEHVqYDVh5XiDSW8Dt9sG1UyHvOE6nSTtQguaO4vor4Fp@noxkpqjq8ufxq969ut0v5p3m:27017/orisoxin?directConnection=true&authSource=admin', { - // mongoose.connect('mongodb://root:asrerb6udsf13sdfb6@srv-captain--danak-mongo-2:27017/orisoxin?authSource=admin', { -// mongoose.connect('mongodb://localhost:27017/OrisOxin', { +const mongoUri = process.env.MONGODB_URI || 'mongodb://root:e9a15xftSaqNgR1fNMSUEHVqYDVh5XiDSW8Dt9sG1UyHvOE6nSTtQguaO4vor4Fp@noxkpqjq8ufxq969ut0v5p3m:27017/orisoxin?directConnection=true&authSource=admin' + +mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false,