-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
34 lines (28 loc) · 894 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
34
const express = require('express');
const { notFound } = require('@hapi/boom');
const bautaJS = require('./server/instances/bauta');
(async () => {
// Please, add helmet or other security library on your production API.
const app = express();
const router = await bautaJS.buildRouter();
app.use('/', router);
/* Error handler */
// 404 error
app.use((req, res, next) => next(notFound()));
// Error handler
/* eslint-disable-next-line */
app.use((err, req, res, next) => {
// eslint-disable-next-line no-console
console.error(err);
res
.status(err.output ? err.output.statusCode : err.status || 500)
.json(err.errors || { message: err.message });
});
app.listen(8080, err => {
if (err) throw err;
bautaJS.logger.info('Server listening on localhost: 8080');
});
})();
process.on('unhandledRejection', () => {
process.exit(1);
});