-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.16 KB
/
index.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
const express = require("express");
const _ = require("lodash");
const app = express();
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const config = require("./config/config");
const port = config.port;
const url = config.url;
mongoose.connect(url, {useNewUrlParser: true}, function(err, result){
if(err){
res.status(500).json({"message" : "Unable to connect to mongoDb"})
}
})
app.all("*", function (req, res, next) {
console.info("METHOD: " + req.method + "," + " URL: " + req.originalUrl);
return next();
});
app.use(bodyParser.json(
{
limit: '1mb',
type:'application/json'
}
));
app.use(bodyParser.urlencoded(
{
extended: false
}
));
require("../bigApp/routes/routes")(app);
app.get('/', function(req, res){
res.send('Hello Client');
})
app.use(function (err, req, res, next){
console.error(err.message);
console.error(err.stack);
res.status(_.get(err, "output.statusCode") || 500).json({
message : err.message
// error : err
});
})
app.listen(port, function(req, res){
console.log("Server listening on port " + `${port}`);
})