-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.28 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const cors = require("cors");
const express = require("express");
const fs = require("fs");
const http = require("http");
const https = require("https");
const app = express();
const certDirPath = "./.dev";
const port = 8082;
app.use(cors());
app.use(express.json({ limit: "50MB" }));
app.post("/remote-logger", (req, res) => {
fs.writeFileSync("./logs.txt", req.body.join("\n"), {
flag: "a"
});
res.sendStatus(201);
});
if (certDirPath) {
const tlsCertPath = `${certDirPath}/dev.crt`;
const tlsKeyPath = `${certDirPath}/dev.key`;
try {
const files = fs.readdirSync(certDirPath);
const ca = files.filter(file => {
return file.startsWith("i") && file.endsWith(".crt");
});
const tls = {
key: fs.readFileSync(tlsKeyPath, "utf8"),
cert: fs.readFileSync(tlsCertPath, "utf8")
};
if (ca) {
tls.ca = ca.map(c => {
return fs.readFileSync(`${certDirPath}/${c}`, "utf8");
});
}
const httpsServer = https.createServer(tls, app);
httpsServer.listen(port);
console.log(`Listening (https) on port ${port}`);
return;
} catch (e) {
console.error("Could not start server in https mode: ", e);
}
}
const httpServer = http.createServer(app);
httpServer.listen(port);
console.log(`Listening (http) on port ${port}`);