-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (38 loc) · 1.07 KB
/
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
37
38
39
40
41
42
43
44
require("dotenv").config();
const fastify = require("fastify")();
const fastifyCron = require("fastify-cron");
const axios = require("axios");
const { defaultError } = require("./schemas/shared");
const { createDefaultEnv } = require("./util/env");
const { getAdminAccessToken } = require("./routes/admin");
fastify.register(require("fastify-cors"), {
origin: "*",
});
fastify.register(require("./routes/admin").AdminRoutes);
fastify.register(require("./routes/user").UserRoutes);
fastify.register(require("./routes/role").RoleRoutes);
fastify.addSchema(defaultError);
fastify.register(fastifyCron, {
jobs: [
{
cronTime: "*/30 * * * * *",
onTick: async (server) => {
await getAdminAccessToken();
},
},
],
});
const start = async () => {
try {
createDefaultEnv();
fastify.listen(process.env.PORT, "0.0.0.0", async function (err, address) {
console.log(`Listening on ${address}`);
fastify.cron.startAllJobs();
await getAdminAccessToken();
});
} catch (err) {
console.log(err);
process.exit(1);
}
};
start();