forked from project-sunbird/ml-core-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
72 lines (57 loc) · 1.69 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
71
72
/**
* name : app.js
* author : Aman Jung Karki
* created-date : 09-Dec-2019
* Description : Root file.
*/
require("dotenv").config();
//express
const express = require("express");
let app = express();
// Health check
require("./healthCheck")(app);
require("./config");
require("./config/globals")();
let environmentData = require("./envVariables")();
if(!environmentData.success) {
console.log("Server could not start . Not all environment variable is provided");
process.exit();
}
let router = require("./routes");
//required modules
const fileUpload = require("express-fileupload");
const bodyParser = require("body-parser");
const cors = require("cors");
var fs = require("fs");
var path = require("path");
var 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(
"%s %s on %s from ",
req.method,
req.url,
new Date(),
req.headers["user-agent"]
);
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();
});
//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;