forked from microobs/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (29 loc) · 796 Bytes
/
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
const app = require('express')(),
bodyParser = require('body-parser'),
debug = require('debug')('gateway:errors');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// handle favicon
app.use(function (request, response, next) {
if (request.url === 'favicon.ico') {
response.writeHead(200, { 'Content-Type': 'image/x-icon' });
response.end('');
} else {
next();
}
});
// routes
app.use('/', require('./routes'));
// error handling
app.use(function (request, response, next) {
let err = new Error('Not Found');
err.status = 404;
//console.log(err);
debug(err);
next(err);
});
app.use(function (err, request, response, next) {
response.status(err.status || 500).json({ error: err.message });
});
// listener
module.exports = app;