forked from antixenoinitiative/thargoid.watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (26 loc) · 850 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* This is the webserver code for the Thargoid.Watch website. Live website can be found at https://www.thargoid.watch
*
* IMPORTANT: If you are running this locally, ensure you create a .env file and include the following two variables.
*
* PORT=<port number>
* MODE=DEV
*
*/
require("dotenv").config();
const express = require('express');
const app = express();
const PORT = process.env.PORT;
const MODE = process.env.MODE;
function requireHTTPS(req, res, next) {
if (req.headers["x-forwarded-proto"] == "http" && MODE != "DEV") {
return res.redirect(301, "https://" + req.hostname+req.url);
}
next();
}
app.use(requireHTTPS);
app.use(express.static('public'));
app.get('/',function(req,res) {
res.sendFile('public/index.html');
});
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`));