-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (45 loc) · 1.37 KB
/
app.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
const compression = require('compression')
const express = require("express");
const app = express();
const port = 3002;
const fs = require("fs");
app.use(compression())
app.use((req, res, next) => {
res.setHeader(
"Access-Control-Allow-Origin",
"https://lostmypillow.github.io/"
);
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173");
res.setHeader(
"Access-Control-Allow-Methods",
"GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS,CONNECT,TRACE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type, Authorization, X-Content-Type-Options, Accept, X-Requested-With, Origin, Access-Control-Request-Method, Access-Control-Request-Headers"
);
res.setHeader("Access-Control-Allow-Credentials", true);
res.setHeader("Access-Control-Allow-Private-Network", true);
res.setHeader("Access-Control-Max-Age", 7200);
next();
});
app.get("/", async (req, res) => {
// await betterCheck();
let path =
"./split_data_part" +
(Math.floor(Math.random() * 6) + 1).toString() +
".json";
let quote = JSON.parse(
fs.readFileSync(require.resolve(path), {
encoding: "utf8",
flag: "r",
})
);
res.json(quote[Math.floor(Math.random() * quote.length)]);
});
app.get("/wake", async (req, res) => {
res.send("system online");
});
app.listen(port, '0.0.0.0', () => {
console.log(`JQuotes listening on port 3002`);
});