9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-11-26 07:27:30 +00:00

🎿🙋 Checkpoint

./server.js:933874/12847
This commit is contained in:
Glitch (hello-express) 2019-12-08 23:35:30 +00:00
parent 10648aad70
commit 3de62c0b4b

View File

@ -20,8 +20,22 @@ try {
} catch (err) {} } catch (err) {}
app.use(express.static("public")); app.use(express.static("public"));
app.enable("trust proxy"); // needed for HTTP -> HTTPS redirect and successful test against req.secure
const redirectToHTTPS = (req, res, next) => {
if (req.secure) {
// request was via https, so do no special handling
next();
} else {
// request was via http, so redirect to https
res.redirect("https://" + req.headers.host + req.url);
}
};
app.get("/", (req, res) => { app.get("/", (req, res) => {
if (!req.secure) {
return res.redirect(["https://", req.get("Host"), req.baseUrl].join(""));
}
res.sendFile(__dirname + "/views/index.html"); res.sendFile(__dirname + "/views/index.html");
}); });
@ -120,7 +134,7 @@ request.post(
lastClosed < lastSeen lastClosed < lastSeen
) { ) {
// the Fuz is newly closed, notify on matrix and write file to survive reboot // the Fuz is newly closed, notify on matrix and write file to survive reboot
//https.post ... send message to Fuz process.env.MATRIXROOM //https.put ... send message to Fuz process.env.MATRIXROOM
request.put( request.put(
{ {
url: url: