-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (22 loc) · 774 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
require('./config/config.js');
require('./models/db.js');
require('./config/passportConfig');
const express = require('express');
const bodyparser = require('body-parser');
const cors = require('cors');
const passport = require('passport');
const rtsIndex = require ('./routes/index.router.js');
var app = express();
//middleware
app.use(bodyparser.json());
app.use(cors());
app.use(passport.initialize());
app.use('/api',rtsIndex);
app.use((err,req,res,next)=>{
if(err.name == 'ValidationError'){
var valErrors = [];
Object.keys(err.errors).forEach(key => valErrors.push(err.errors[key].message));
res.status(422).send(valErrors);
}
});
app.listen(process.env.PORT,function(){console.log('Server started at port:'+ process.env.PORT)});