I'm trying to create a middleware to redirect all my routes to https, I think I need a middleware so I've created a redirect.js
file in the middleware folder of Nuxt and then I've added this to nuxt.config.js
:
router: {
middleware: ["redirect"]
},
And here is my redirect.js
file that gives me a server error:
export default function({ app }) {
if (process.env.NODE_ENV === "production") {
if (app.context.req.header("x-forwarded-proto") !== "https") {
app.context.res.redirect(`https://${app.context.req.header("host")}${app.context.req.url}`);
}
}
}