Merge pull request #10 from nbitzz/express-ssl-force

Force SSL through expressjs
This commit is contained in:
May 2023-10-01 10:59:13 -07:00 committed by GitHub
commit a4bbbf8d53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -24,5 +24,8 @@
"send": {
"from": "mono@fyle.uk"
}
}
},
"trustProxy": true,
"forceSSL": true
}

View file

@ -28,6 +28,15 @@ app.use("/static/js",express.static("out/client"))
app.use(cookieParser())
// check for ssl, if not redirect
if (config.trustProxy) app.enable("trust proxy")
if (config.forceSSL) {
app.use((req,res,next) => {
if (req.protocol == "http") res.redirect(`https://${req.get("host")}${req.originalUrl}`)
else next()
})
}
app.get("/server",(req,res) => {
res.send(JSON.stringify({
...config,