-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (33 loc) · 1.08 KB
/
index.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
52
53
54
55
const fastify = require("fastify")({
logger: true,
disableRequestLogging: true,
});
const { mongoInit } = require("./DB/mongoInit");
const { version } = require("./package.json");
// ############################################################
// ENV
// ############################################################
require("entor")();
// ############################################################
// Fastify
// ############################################################
const port = process.env.PORT || 9999;
(async() => {
fastify.register(require("fastify-cors"), { // https://github.com/fastify/fastify-cors
origin: "*",
// origin: process.env.MODE === "prod" ? ["https://miweb.app"] : "*",
methods: ["OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE"],
});
fastify.register(require("./router"), /*{prefix: "/api"}*/);
await mongoInit();
try {
await fastify.listen(port);
} catch (err) {
fastify.log.error(err);
process.exit(1);
};
fastify.ready(err => {
if (err) throw err;
console.log( ` ✅ Fastify (port: ${port})` );
});
})();