forked from BTE-Germany/EventBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
22 lines (19 loc) · 730 Bytes
/
Copy pathapi.js
File metadata and controls
22 lines (19 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const Fastify = require('fastify');
const cors = require('@fastify/cors');
const fs = require("fs");
module.exports = {
start: async () => {
const fastify = Fastify();
const routeFiles = fs.readdirSync('./api/endpoint').filter(file => file.endsWith('.js'));
for (const file of routeFiles) {
let data = require(`./endpoint/${file}`);
console.log(new Date().toLocaleString(), `Registering route: /${data.method} ${data.path}`);
fastify.route(data);
}
fastify.register(cors, {
origin: true,
methods: ['GET', 'POST', 'PUT', 'DELETE']
});
await fastify.listen({port: process.env.PORT, host: '0.0.0.0'});
}
}