-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
70 lines (42 loc) · 1.23 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express');
const pg = require ('pg');
//const dontenv = require('dotenv').config()
const bodyParser = require('body-parser');
const morgan = require ('morgan');
const app = express();
//import 'babel-polyfill';
//const bcrypt = require ('bcrypt');
const authRoutes = require('./apis/routes/auth');
const bookingsRoutes = require('./apis/routes/bookings');
const tripsRoutes = require('./apis/routes/trips');
const dbConn = require ('./db/conn');
//middlewares
//const port = 5000;
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(morgan('dev'));
//handling endpoint requests
app.use('/auth', authRoutes) ;
app.use('/bookings', bookingsRoutes) ;
app.use('/trips', tripsRoutes) ;
//error handling 1
app.use(function(req,res,next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
//error handling 2
app.use(function(req, res, next) {
res.status(err.status || 500);
res.json({
message : err.message,
error: req.app.get('env') === 'development' ? err :{}
});
});
/*app.get('/', (req, res) => {
res.status(200).send({
message :'success'
})
})*/
//const server = http.createSrver(app);
module.exports = app;