I use NextJS and React. My server.js
file, looks like this:
const express = require('express')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare()
.then(() => {
const server = express()
var countrycode = ''
server.post('/', (req, res) => {
countrycode = req.body.code
})
server.get('/', (req, res) => {
console.log(res)
if (countrycode == 'DE') {
return app.render(req, res, '/de', req.query)
} else {
return app.render(req, res, '/', req.query)
}
})
})
})
i try to save the req.body.code
value inside the outside variable var countrycode
but it doesn't work. I need to take this step so I can check this value in the server.get
function. If the client comes from Germany, the German side should be returned, otherwise the English.
Where is my mistake? What exactly do I need to change? Thanks for your answer