-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (42 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
44
45
46
47
48
49
50
51
const axios = require("axios");
const cors = require("cors");
const express = require("express");
const path = require("path");
const app = express();
const port = process.env.PORT || 80;
app.use(cors());
app.use(express.static(path.join(__dirname, "docs")));
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "docs", "index.html"));
});
// This displays message that the server running and listening to specified port
app.listen(port, () => console.log(`Listening on port ${port}`));
app.get("/heartbeat-enabled", function (req, res) {
return res.send({ enabled: true });
});
app.get("/heartbeat", (req, res) => {
// await new Promise(resolve => setTimeout(resolve, 2000));
const handleResponse = response => {
console.log(
"heartbeat",
req.query.page,
response?.status,
response?.statusText
);
if (!response) {
res.send({
status: null,
text: null,
});
} else {
res.send({
status: response.status,
text: response.statusText,
});
}
};
axios
.get(req.query.page)
.then(handleResponse)
.catch(({ response }) => handleResponse(response));
});