-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (60 loc) · 2.17 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import '#utils/ApiError.js';
import parser from 'body-parser';
import express from 'express';
import fileupload from 'express-fileupload';
// Import { scheduleInit } from "#scheduler/Service/schedulerService.js";
import expressListRoutes from 'express-list-routes';
import session from 'express-session';
import helmet from 'helmet';
import defaultMiddleware from '#middlewares/default.middleware.js';
import { setupCors, setupHtmlErrorInterceptor, setupRateLimiter, setupResponseInterceptor, setupTimeout, setupValidationErrorInterceptor } from '#middlewares/server.middleware.js';
import seedSuperAdmin from '#user/Seed/superadmin.seed.js';
import morgalApiLogger from '#utils/Logger/api.logger.js';
import overrideConsole from '#utils/Logger/console.logger.js';
import { getTenantDB } from '#utils/Mongo/mongo.connection.js';
import registerRoutes from '#utils/registerRoutes.js';
const app = express();
app.use(
session({
// Save new sessions
cookie: {
// Set to true for HTTPS in production
httpOnly: true,
// Protect session cookie from client-side JS
maxAge: 24 * 60 * 60 * 1000,
secure: false // 1 day expiration
},
// Use a strong secret key
resave: false,
// Don't resave unchanged sessions
saveUninitialized: true,
secret: 'saransh'
})
);
app.use(defaultMiddleware());
overrideConsole();
/*
* console.debug('======================ENV======================');
* console.debug(process.env);
* console.debug('======================ENV======================');
*/
await getTenantDB().then(() => seedSuperAdmin());
app.use(parser.json());
app.use(parser.urlencoded({ extended: true }));
app.use(helmet());
app.use(fileupload());
app.enable('strict routing');
setupCors(app);
setupTimeout(app);
setupRateLimiter(app);
morgalApiLogger(app);
setupHtmlErrorInterceptor(app);
setupResponseInterceptor(app);
await registerRoutes(app);
expressListRoutes(app);
setupValidationErrorInterceptor(app);
app.listen(process.env.PORT, () => {
console.success(`Server started on PORT ${process.env.PORT} PROCESS_ID ${process.pid}`);
// ScheduleInit();
});
process.on('uncaughtException', (err) => console.log('Caught uncought exception: ', err));