forked from chriswhong/express-geosupport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (24 loc) · 744 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
// simple express app to serve up custom APIs
const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes');
const app = express();
// allows CORS
app.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type,Authorization');
next();
});
app.use(bodyParser.json());
app.use('/', routes);
// catch 404 and forward to error handler
app.use((err, req, res, next) => {
if (err.name === 'UnauthorizedError') {
res.status(401).send({
error: 'invalid token',
});
}
next(err);
});
module.exports = app;