-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (29 loc) · 807 Bytes
/
Copy pathapp.js
File metadata and controls
36 lines (29 loc) · 807 Bytes
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const routes = require('./routes.js');
// Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// Routers
app.use('/', routes);
// http access-control
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
// Error handler
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
message: err.message,
error: req.app.get('env') === 'development' ? err : {}
});
});
// PORT
const port = 5000;
app.listen(port, () => {
console.log(`listening on port ${ port }...`);
});
module.exports = app;