-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
72 lines (52 loc) · 3.69 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const express = require("express");
const path = require("path");
const https = require('https');
const fs = require('fs');
console.log(`
██████╗ ██████╗ ██████╗ ███████╗ ███╗ ██╗ ██████╗ ██████╗ ███████╗ ███████╗███████╗██████╗ ██╗ ██╗██╗ ██████╗███████╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝ ████╗ ██║██╔═══██╗██╔══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗██║ ██║██║██╔════╝██╔════╝
██║ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║██║ ██║██║ ██║█████╗ ███████╗█████╗ ██████╔╝██║ ██║██║██║ █████╗
██║ ██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║██║ ██║██║ ██║██╔══╝ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║██║ ██╔══╝
╚██████╗╚██████╔╝██║ ██║███████╗ ██║ ╚████║╚██████╔╝██████╔╝███████╗ ███████║███████╗██║ ██║ ╚████╔╝ ██║╚██████╗███████╗
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═════╝╚══════╝
`);
console.log("Root directory is located at : " + __dirname);
const app = express();
console.log("Setting up static file routes");
app.use("/static", express.static(path.resolve(__dirname, "wwwroot", "static")));
console.log("Setting HTML routes");
app.get("/", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "index.html"));
});
app.get("/ServiceWorker.js", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "ServiceWorker.js"));
});
app.get("/manifest.json", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "manifest.json"));
});
app.get("/favicon.ico", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "favicon.ico"));
});
app.get("/loading", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "loading.html"));
});
app.get("/*", (req, res) => {
console.log("Requested url : " + req.originalUrl);
res.sendFile(path.resolve(__dirname, "wwwroot", "index.html"));
});
/*
const options = {
key: fs.readFileSync('cert/key.pem'),
cert: fs.readFileSync('cert/cert.pem')
};
var server = https.createServer(options, app);
server.listen(443, () => {
console.log("Listenning for https requests on PORT 443.\nReady.");
});
*/
app.listen(process.env.PORT || 80, () => console.log("Listenning for http requests on PORT 80.\nReady."));