-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (34 loc) · 1.29 KB
/
main.js
File metadata and controls
41 lines (34 loc) · 1.29 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
const fastify = require("fastify")({ logger: { level: "info" } });
const helmet = require("@fastify/helmet");
require("dotenv").config();
// no sé por qué las jodidas peticiiones piden un favicon. Con esto
// evitamos en el log q ponga que no existe.
fastify.addHook("onRequest", (request, reply, done) => {
if (request.url === "/favicon.ico") {
reply.code(204).send();
} else {
done();
}
});
// el asunto es este: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
// cuando hace un POST realmente pregunta antes al servidor con el método OPTIONS...
fastify.register(require("@fastify/cors"), {
origin: ["http://localhost:3000"],
methods: "GET,POST,OPTIONS",
});
fastify.register(require("@fastify/rate-limit"), {
max: 180,
timeWindow: "1 minute",
});
// We declare a route
fastify.register(require("./src/routes/general"), { prefix: "/general" });
fastify.register(require("./src/routes/works"), { prefix: "/works" });
fastify.register(require("./src/routes/houses"), { prefix: "/houses" });
fastify.register(require("./src/routes/resolutions"), { prefix: "/chapters" });
fastify.register(require("./src/routes/bishops"), { prefix: "/bishops" });
fastify.listen({ port: process.env.PORT }, (err) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
});