Subdomain redirect to https with Heroku & NodeJS Middleware

Hello,

I have my server set up on heroku with a custom domain. I also have ssl provided by heroku.

But it seems that heroku doesn’t redirect http requests to https by default.

After looking around it seems that a simple node middleware can do the job:

if(process.env.NODE_ENV === ‘production’) {
app.use((req, res, next) => {
if (req.header(‘x-forwarded-proto’) !== ‘https’)
res.redirect(https://${req.header('host')}${req.url})
else
next()
})
}

From:

My question is where do I insert middleware in wappler without breaking anything ?

Thanks

Community Page
Last updated: