-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
74 lines (59 loc) · 1.5 KB
/
Copy pathserver.js
File metadata and controls
74 lines (59 loc) · 1.5 KB
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
73
74
import "dotenv/config";
import express from "express";
import rateLimit from "express-rate-limit";
import bodyParser from "body-parser";
import imdb from "./imdb.js";
import proxy from "./proxy.js";
const { PORT = 4000 } = process.env;
console.log("Setting shotit-meta-service...");
const app = express();
app.disable("x-powered-by");
app.set("trust proxy", 1);
app.use((req, res, next) => {
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
res.set("Access-Control-Allow-Headers", "Content-Type, x-trace-secret");
next();
});
app.use(
rateLimit({
max: 100, // limit each IP to 100 requests
windowMs: 1000, // per second
delayMs: 0, // disable delaying - full speed until the max limit is reached
})
);
app.use(
bodyParser.raw({
type: ["image/jpeg", "image/png"],
limit: "25mb",
})
);
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use((req, res, next) => {
const startTime = performance.now();
console.log("=>", new Date().toISOString(), req.ip, req.path);
res.on("finish", () => {
console.log(
"<=",
new Date().toISOString(),
req.ip,
req.path,
res.statusCode,
`${(performance.now() - startTime).toFixed(0)}ms`
);
});
next();
});
app.get("/", (req, res) => {
return res.send(`OK`);
});
app.post("/imdb", imdb);
app.get("/proxy", proxy);
app.listen(PORT, "0.0.0.0", () =>
console.log(`server listening on port ${PORT}`)
);