|
1 | | -import "./instrument"; |
| 1 | +import "./instrument" |
2 | 2 |
|
3 | | -import { NestFactory } from '@nestjs/core'; |
4 | | -import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express'; |
5 | | -import cookieParser from 'cookie-parser'; |
6 | | -import express, { Response } from 'express'; |
7 | | -import passport from 'passport'; |
8 | | -import { rawBodyBuffer } from '~/_common/middlewares/raw-body-buffer.middleware'; |
9 | | -import { getLogLevel } from './_common/functions/get-log-level'; |
10 | | -import { AppModule } from './app.module'; |
11 | | -import configInstance from './config'; |
12 | | -import { InternalLogger } from './core/logger/internal.logger'; |
13 | | -import { readFileSync } from 'fs'; |
14 | | -import * as http from 'http'; |
15 | | -import * as https from 'https'; |
16 | | -import { ShutdownObserver } from './_common/observers/shutdown.observer'; |
17 | | -import { useContainer } from 'class-validator'; |
| 3 | +import { NestFactory } from '@nestjs/core' |
| 4 | +import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express' |
| 5 | +import cookieParser from 'cookie-parser' |
| 6 | +import express, { Response } from 'express' |
| 7 | +import passport from 'passport' |
| 8 | +import { rawBodyBuffer } from '~/_common/middlewares/raw-body-buffer.middleware' |
| 9 | +import { getLogLevel } from './_common/functions/get-log-level' |
| 10 | +import { AppModule } from './app.module' |
| 11 | +import configInstance from './config' |
| 12 | +import { InternalLogger } from './core/logger/internal.logger' |
| 13 | +import { readFileSync } from 'fs' |
| 14 | +import * as http from 'http' |
| 15 | +import * as https from 'https' |
| 16 | +import { ShutdownObserver } from './_common/observers/shutdown.observer' |
| 17 | +import { useContainer } from 'class-validator' |
18 | 18 |
|
19 | 19 | declare const module: any; |
20 | 20 | (async (): Promise<void> => { |
21 | 21 | const cfg = configInstance(); |
22 | 22 | const logger = new InternalLogger({ |
23 | 23 | logLevel: getLogLevel(cfg?.application?.logLevel), |
24 | 24 | mongoose: cfg?.mongoose, |
25 | | - }); |
26 | | - await logger.initialize(); |
| 25 | + }) |
| 26 | + await logger.initialize() |
27 | 27 |
|
28 | | - let extraOptions = <any>{}; |
| 28 | + let extraOptions = <any>{} |
29 | 29 | if (cfg.application?.https?.enabled) { |
30 | 30 | try { |
31 | 31 | extraOptions.httpsOptions = { |
32 | 32 | key: readFileSync(cfg.application?.https?.key), |
33 | 33 | cert: readFileSync(cfg.application?.https?.cert), |
34 | 34 | }; |
35 | | - logger.log('HTTPS is enabled !'); |
| 35 | + logger.log('HTTPS is enabled !') |
36 | 36 | } catch (error) { |
37 | | - logger.error('Error while reading https key and cert', error); |
| 37 | + logger.error('Error while reading https key and cert', error) |
38 | 38 | } |
39 | 39 | } |
40 | 40 |
|
41 | | - const server = express(); |
| 41 | + const server = express() |
42 | 42 | const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(server), { |
43 | 43 | snapshot: true, |
44 | 44 | bodyParser: false, |
45 | 45 | rawBody: true, |
46 | 46 | cors: true, |
47 | 47 | logger, |
48 | 48 | ...extraOptions, |
49 | | - }); |
| 49 | + }) |
50 | 50 | app.use((_: any, res: Response, next: () => void) => { |
51 | 51 | res.removeHeader('x-powered-by'); |
52 | 52 | next(); |
53 | | - }); |
54 | | - app.use(passport.initialize()); |
55 | | - app.use(rawBodyBuffer(cfg?.application?.bodyParser)); |
56 | | - app.use(cookieParser()); |
| 53 | + }) |
| 54 | + app.use(passport.initialize()) |
| 55 | + app.use(rawBodyBuffer(cfg?.application?.bodyParser)) |
| 56 | + app.use(cookieParser()) |
57 | 57 | if (process.env.production !== 'production') { |
58 | | - await (await import('./swagger')).default(app); |
| 58 | + await (await import('./swagger')).default(app) |
59 | 59 | } |
60 | 60 |
|
61 | | - useContainer(app.select(AppModule), { fallbackOnErrors: true }); |
| 61 | + useContainer(app.select(AppModule), { fallbackOnErrors: true }) |
62 | 62 |
|
63 | | - await app.init(); |
| 63 | + await app.init() |
64 | 64 |
|
65 | | - const shutdownObserver = app.get(ShutdownObserver); |
66 | | - const httpServer = http.createServer(server).listen(4000); |
| 65 | + const shutdownObserver = app.get(ShutdownObserver) |
| 66 | + const httpServer = http.createServer(server).listen(4000) |
67 | 67 |
|
68 | 68 | // Set timeout to 0 for SSE connections |
69 | | - httpServer.timeout = 0; |
70 | | - httpServer.keepAliveTimeout = 0; |
71 | | - httpServer.headersTimeout = 0; |
| 69 | + httpServer.timeout = 0 |
| 70 | + httpServer.keepAliveTimeout = 0 |
| 71 | + httpServer.headersTimeout = 0 |
72 | 72 |
|
73 | | - shutdownObserver.addHttpServer(httpServer); |
74 | | - logger.log(`Sesame - Orchestrator is READY on <http://127.0.0.1:4000> !`); |
| 73 | + shutdownObserver.addHttpServer(httpServer) |
| 74 | + logger.log(`Sesame - Orchestrator is READY on <http://127.0.0.1:4000> !`) |
75 | 75 |
|
76 | 76 | if (cfg.application?.https?.enabled) { |
77 | | - const httpsServer = https.createServer(extraOptions.httpsOptions!, server).listen(4443); |
| 77 | + const httpsServer = https.createServer(extraOptions.httpsOptions!, server).listen(4443) |
78 | 78 |
|
79 | 79 | // Set timeout to 0 for SSE connections |
80 | | - httpsServer.timeout = 0; |
81 | | - httpsServer.keepAliveTimeout = 0; |
82 | | - httpsServer.headersTimeout = 0; |
| 80 | + httpsServer.timeout = 0 |
| 81 | + httpsServer.keepAliveTimeout = 0 |
| 82 | + httpsServer.headersTimeout = 0 |
83 | 83 |
|
84 | | - shutdownObserver.addHttpServer(httpsServer); |
85 | | - logger.log(`Sesame - Orchestrator is READY on <https://127.0.0.1:4443> !`); |
| 84 | + shutdownObserver.addHttpServer(httpsServer) |
| 85 | + logger.log(`Sesame - Orchestrator is READY on <https://127.0.0.1:4443> !`) |
86 | 86 | } |
87 | 87 |
|
88 | 88 | if (module.hot) { |
89 | | - module.hot.accept(); |
90 | | - module.hot.dispose((): Promise<void> => app.close()); |
| 89 | + module.hot.accept() |
| 90 | + module.hot.dispose((): Promise<void> => app.close()) |
91 | 91 | } |
92 | 92 | })(); |
0 commit comments