-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 772 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 772 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
require('./config/config');
require('./db')
require('./config/passportConfig');
const express = require('express');
const bodyParser = require('body-parser')
const cors = require('cors')
const passport = require('passport')
const rtxIndex = require('./routes/index.router')
var app = express()
// middleware
app.use(bodyParser.json());
app.use(cors());
app.use(passport.initialize());
app.use('/api', rtxIndex);
//error handler
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, () => {
console.log('Express Server started at port: ' + process.env.PORT);
});