Hi, I have a freenom domain and I was wondering what’s the easiest free way to force HTTPS for the domain?
Hey @fqriss,
Is your project a Node.js project? If it is, you can add this code to your server JS file:
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);
Or, you could set up Cloudflare and force it.
2 Likes
It only works when I use the Glitch domain, I need it to redirect when I use the custom domain.
Haven’t used Cloudflare before, can you send me a guide on how to set it up?
This is from Cloudflare’s website:
I think I got everything with Cloudflare set up. Does it take time to update, cause it’s still not forcing HTTPS for the domain?
You have to set HTTPS forcing in the settings
DNS takes up to 24 hours to update, so give it some time.
Alright, I’ll post an update tomorrow if it worked or not.
1 Like
That worked, thanks.
1 Like