-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (33 loc) · 1.16 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
require('dotenv').config();
var express = require('express');
const cors = require('cors');
var bodyParser = require('body-parser');
var helmet=require("helmet");
const config = require('./config/config')
const OutletRoutes = require('./routers/OutletRoutes')
var app = express();
app.use(helmet())
app.use(cors());
//Add middlewares to entire webApp
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use('/api/v1/outlets', OutletRoutes)
//==============================If api address not found=======================//
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
console.log(err)
res.status(err.status || 500).json(
{message: err.message});
});
if (app.get('env') === 'dev' || app.get('env') === 'local') {
console.log("SERVER IS RUNNING ON PORT: ",config.port.portNumber,"on ENV: ",process.env.NODE_ENV)
app.listen(config.port.portNumber);
}else{
console.log("no env selected")
}
module.exports = app;