-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
36 lines (29 loc) · 824 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
import { dirname, resolve } from "path";
import fastify from "fastify";
import fastifyStatic from "@fastify/static";
import fastifyRateLimit from "@fastify/rate-limit";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = fastify();
const PORT = process.env.PORT || 6090;
app.register(fastifyStatic, {
root: resolve(__dirname, "dist"),
prefix: "/",
wildcard: false,
});
app.register(fastifyRateLimit, {
max: 300,
timeWindow: "1 minute",
});
app.setNotFoundHandler((req, reply) => {
reply.sendFile("index.html");
});
app.listen({ port: PORT, host: "0.0.0.0" }, (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server is running on http://0.0.0.0:${PORT}`);
});
export default app;