Expressjs version: https://glitch.com/edit/#!/force-http-or-https
Polka version: https://glitch.com/edit/#!/force-http-or-https-polka
Glitch now supports both HTTP and HTTPS, I did not find any way to force HTTP/HTTPS from the settings so I made this demo project instructions are in the code!
3 Likes
Fantastic… I was afraid I wouldn’t be able to use my retro gadgets with glitch. The HTTP forcing works.
1 Like
If you’re using Express, paste this code in 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){
console.log("https, yo")
return next()
} else {
console.log("just http")
res.redirect('https://' + req.hostname + req.url);
}
}
app.all('*', checkHttps)