Force HTTPS Custom domain

I’m trying to make my domain always go to https, but even using cloudflare, it doesn’t redirect, it always sends me to a large url

Does anyone know how to fix it?

1 Like

Hey @DoginUwU,

Pasting this code in your server.js can also force HTTPS for your website:

function checkHttps(req, res, next){
  // protocol check, if http, redirect to https
  
  if(req.get('X-Forwarded-Proto').indexOf("https")!=-1){
    return next()
  } else {
    res.redirect('https://' + req.hostname + req.url);
  }
}

app.all('*', checkHttps);

Hope this helps!

He keeps redirecting me to the large URL :c

and always req.get('X-Forwarded-Proto') returns https

I would recommend using Cloudfare. You will have to change your current name servers to Cloudfare ones and once you have done that you can force encryption.

I was already using cloudflare, even with the option to force HTTPS active ;-;

Interesting. You did the setup correctly?

Yes, I’ve been messing with cloudflare for a long time, but this https never happened before

Hmm. Sorry I don’t know what to say!
It looks like everything is correct.

1 Like

I actually just visited your website I could not view it without HTTPS.

Try using http://anigiri.ga?lang=pt-br

It works when you don’t have the language parameter set

Yep, still gives me HTTPS.

HTTPS but at a large URL?

Screenshot 2020-03-16 at 5.06.56 PM

What?? Here he sends me to this URL

Thats odd.
Try view the project details of that page.
https://glitch.com/~(project url name here)

I didn’t find anything about this url. I have no more ideas than can be

The long is not a shw.io URL either, it’s just a Glitch project with a very long name…