-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (35 loc) · 1.26 KB
/
app.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
const express = require('express');
const app = express();
const port = process.env.PORT || 7070;
const bodyParser = require('body-parser');
const requestLogger = require('morgan');
const responseHandler = require('./core/lib/response-handler');
const requestParser = require('./core/lib/request-parser');
const logger = require('./core/lib/logger');
const routes = require('./routes/index');
const worker = require('./workers/process-receipts');
worker();
app.use(requestLogger('common', { stream: logger.stream }));
app.use(bodyParser.json());
app.use(requestParser());
app.use('/', routes);
app.get('/health', (req, res) => {
res.status(200).json({ message: 'Service Up & Running' });
});
app.get('/', (req, res) => {
res.status(200).json({ message: 'OK' });
});
app.listen(port, () => {
logger.info(`Example app listening on port ${port}`);
});
// eslint-disable-next-line no-unused-vars
app.use((req, res, next) => {
res.status(404).json({ message: 'Invalid Route' });
});
// error handler
// The `next` var needs to be left below to ensure express picks this function as error handler
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
logger.error('Error caught by error handler: ', err);
responseHandler.handleError(err, res);
});