Auto Redirect to SSL on Custom Domain

I just deployed a NodeJS app on fly and connected a custom domain. I even generated a certificate. But the thing is when I go to the HTTPS version of the website, I get the secure site but if I go to the HTTP version, it takes to the non-secure site and I want the redirect to happen automatically. What should I do?

Not sure if you use express, but if you do:

const app = express();
app.use(function (req, res, next) {
  if (
    req.get('X-Forwarded-Proto') === 'http' &&
    !['localhost', ''].includes(
      req.get('X-Forwarded-Host')?.split(':')[0] ?? ''
  ) {
    res.redirect('https://' + + req.url);
  } else {

Redirects all http traffic to https, except for localhost and

We’ve just shipped a new feature that handles this for you. It’s a simple configuration option in fly.toml and you should be good to go.