How do I redirect www to no www in Nuxt. I used the code below and it didn't work correctly.
`module.exports = function (req, res, next) {
const host = req.headers.host
const url = req.url
const env = process.env.NODE_ENV
const forceDomain = 'https://site.com'
if (env === 'production' && host === 'www.site.com') {
res.writeHead(301, { Location: forceDomain + url })
return res.end()
}
return next()
}`
I'm using Node as a server with PM2.
Is there any configuration that works before coming to Node? For when HTTPS is enabled it works correctly, so I believe there is something before starting the Node.