-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (28 loc) · 990 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
const fastify = require('fastify')({logger: true});
const validateData = require('./src/validateData');
const saveData = require('./src/saveData');
const config = require('config');
const portNumber = config.get('portNumber') || 3000;
const saveFolder = config.get('saveLocation') || './';
fastify.get('/', function(request, response) {
response.send('OK');
});
fastify.post('/process', async (request, response) => {
fastify.log.info(`Skybook event handler: Received request at ${Date.now()}.`);
if (!validateData(request.body)) {
throw new Error('Data is not in the correct format');
}
saveData(request.body, saveFolder);
fastify.log.info(`Skybook event handler: Completed request at ${Date.now()}.`);
response.send('Success');
});
async function start() {
try {
await fastify.listen(portNumber);
fastify.log.info(`server listening on ${fastify.server.address().port}`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
}
start();