-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (41 loc) · 1003 Bytes
/
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
const express = require("express");
const http = require("http");
const fs = require("fs");
const indexFile = __dirname + "/index.html";
const mdFile = __dirname + "/main.md";
let date = Date.now();
const srv = express();
const port = 3010; // Sync met reload
/**
* Reload-test vanuit client: is er een update gedaan
*/
srv.get("/reload", (req, res) => {
if (chkUpdate())
res.status(200).send();
else
res.status(201).send();
});
srv.get("/", (req, res) => {
res.sendFile(indexFile);
//startWait();
});
srv.use("/", express.static("./"));
srv.use("/builds", express.static("./builds"));
srv.use("/assets/", express.static("./assets"));
srv.listen(port, () => {
console.log(`express listening on port ${port}`);
});
/**
* Update nodig? (20230522)
* @returns
*/
function chkUpdate() {
if (fs.existsSync(mdFile)) {
let stats = fs.statSync(mdFile);
if (!date || (stats["mtimeMs"] > date)) {
date = stats["mtimeMs"];
return true;
}
}
return false;
}