-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.js
69 lines (53 loc) · 1.76 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
/**
* name : app.js.
* author : Aman Karki.
* created-date : 13-July-2020.
* Description : Root file.
*/
require("dotenv").config();
// express
const express = require("express");
const app = express();
// Health check
require("./healthCheck")(app);
// Setup application config, establish DB connections and set global constants.
require("./config/connections");
require("./config/globals")();
// Check if all environment variables are provided.
const environmentData = require("./envVariables")();
if (!environmentData.success) {
console.log("Server could not start . Not all environment variable is provided");
process.exit();
}
//required modules
const fileUpload = require("express-fileupload");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const expressValidator = require('express-validator');
//To enable cors
app.use(cors());
app.use(expressValidator())
app.use(fileUpload());
app.use(bodyParser.json({ limit: "50MB" }));
app.use(bodyParser.urlencoded({ limit: "50MB", extended: false }));
app.use(express.static("public"));
app.all('*', (req, res, next) => {
console.log("-------Request log starts here------------------");
console.log("Request URL: ", req.url);
console.log("Request Headers: ", req.headers);
console.log("Request Body: ", req.body);
console.log("Request Files: ", req.files);
console.log("-------Request log ends here------------------");
next();
});
// Router module
const router = require("./routes");
//add routing
router(app);
//listen to given port
app.listen(process.env.APPLICATION_PORT, () => {
console.log("Environment : " + process.env.APPLICATION_ENV);
console.log("Application is running on the port : " + process.env.APPLICATION_PORT);
});
module.exports = app;