-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (22 loc) · 977 Bytes
/
index.js
File metadata and controls
26 lines (22 loc) · 977 Bytes
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
var express = require("express");
var fs = require("fs-extra");
var path = require("path");
var app = express();
app.listen(8080);
app.use(express.static(path.join(__dirname, "./assets")));
var caPath = path.join(__dirname, "../MonkeyWebConfig/ca_bundle.crt");
var keyPath = path.join(__dirname, "../MonkeyWebConfig/private.key");
var certPath = path.join(__dirname, "../MonkeyWebConfig/certificate.crt");
if (fs.existsSync(caPath) && fs.existsSync(keyPath) && fs.existsSync(certPath)) {
var credentials = {
ca: fs.readFileSync(caPath),
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath)
};
require("https").createServer(credentials, app).listen(443);
// Automatically redirect to https
require("http").createServer(express().use(function (req, res) {
res.redirect("https://" + req.hostname + req.url);
})).listen(80);
}
app.all("*", (_, res) => res.sendFile(path.join(__dirname, "./assets/index.html")));