Skip to content

Commit

Permalink
Merge pull request #10 from nbitzz/express-ssl-force
Browse files Browse the repository at this point in the history
Force SSL through expressjs
  • Loading branch information
nbitzz authored Oct 1, 2023
2 parents fb57af0 + 3bf0e74 commit a4bbbf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"send": {
"from": "[email protected]"
}
}
},

"trustProxy": true,
"forceSSL": true
}
9 changes: 9 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a4bbbf8

Please sign in to comment.