-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (53 loc) · 2.07 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
73
74
75
76
77
78
79
80
81
/* eslint-disable no-unused-vars */
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cookieParser = require('cookie-parser')
const Sentry = require("@sentry/node");
const { systemLogger } = require('./www/initServer/initSysLogger')
// app.use(bodyParser.urlencoded({ limit: "5mb", extended: true, parameterLimit: 1000 }))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: "20mb", extended: true, parameterLimit: 1000 }));
// app.use(bodyParser.urlencoded({ extended: false }));
// app.use(bodyParser.json());
app.use(cookieParser())
const admin = require('firebase-admin');
const serviceAccount = require('./firebaseSetup');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
// databaseURL: "https://your-database-name.firebaseio.com"
});
if (process.env.NODE_ENV === "production") {
//setup cors
const corsSetup = require("./www/appOptions/corsOptions");
app.use(corsSetup);
// set security HTTP headers
const helmetSetup = require("./www/appOptions/helmetOption");
app.use(helmetSetup);
//enable compression
const compressionSetup = require('./www/appOptions/compressionOption')
app.use(compressionSetup);
//rate the limit
const rateLimiterSetup = require("./www/appOptions/rateLimitOption");
app.use(rateLimiterSetup);
//setup sentry
const { initSentry } = require('./www/initServer/initSentry')
initSentry(app);
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
}
//log request handler
const { morgonLogger } = require("./www/logger/morgonLogger");
app.use(morgonLogger)
//setup routes
const { setupAllRoutes } = require('./routes/index')
setupAllRoutes(app)
app.use(Sentry.Handlers.errorHandler());
//response error handler
const { errorHandlerResponser } = require("./www/errorHandler/errorHandler");
app.use(errorHandlerResponser);
//log error handler
const { logErrorResponses } = require("./www/logger/winstonLogger");
app.use(logErrorResponses);
systemLogger.info("App Started.....")
module.exports = app;