-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathserver.js
43 lines (37 loc) · 1.16 KB
/
server.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
32
33
34
35
36
37
38
39
40
41
42
43
var fs = require("fs");
var http = require("http");
var https = require("https");
var privateKey = fs.readFileSync(__dirname + "/key.pem", "utf8");
var certificate = fs.readFileSync(__dirname + "/cert.pem", "utf8");
var path = require("path");
var credentials = { key: privateKey, cert: certificate };
var express = require("express");
var app = express();
app.set("port", process.env.PORT || 9090);
app.use(function(req, res, next) {
if (path.extname(req.path).length > 0) {
next();
} else if (path.dirname(req.path).indexOf("silent_renew") > -1) {
req.url = "/silent_renew.html";
next();
} else {
req.url = "/index.html";
next();
}
});
app
.use(express.static(__dirname + "/dist"))
.get("/", function(req, res) {
res.sendFile("index.html", {
root: __dirname + "/dist"
});
})
.get("/silent_renew.html", function(req, res) {
res.sendFile("silent_renew.html", {
root: __dirname + "/dist"
});
});
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(app.get("port"), function() {
console.log("The server is listening on port", app.get("port"));
});