Skip to content

Commit 4d72d65

Browse files
committed
refactor: harmoniser le style de code et améliorer la lisibilité dans instrument.ts, main.ts et swagger.ts
1 parent 77208a9 commit 4d72d65

File tree

3 files changed

+60
-62
lines changed

3 files changed

+60
-62
lines changed

apps/api/src/instrument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { nodeProfilingIntegration } from '@sentry/profiling-node'
1616
* Si SESAME_SENTRY_DSN n'est pas défini, Sentry reste désactivé et un avertissement est émis.
1717
*/
1818
if (!process.env.SESAME_SENTRY_DSN) {
19-
Logger.warn('SENTRY DSN not provided, Sentry is disabled', 'SentryInit')
19+
Logger.warn('SENTRY DSN not provided, Sentry is disabled', Sentry.constructor.name)
2020
} else {
2121
Sentry.init({
2222
/** DSN de connexion à Sentry */
@@ -70,5 +70,5 @@ if (!process.env.SESAME_SENTRY_DSN) {
7070
Sentry.fsIntegration(),
7171
],
7272
})
73-
Logger.log(`Sentry initialized successfully`, 'SentryInit')
73+
Logger.log(`Sentry initialized successfully`, Sentry.constructor.name)
7474
}

apps/api/src/main.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
import "./instrument";
1+
import "./instrument"
22

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'
1818

1919
declare const module: any;
2020
(async (): Promise<void> => {
2121
const cfg = configInstance();
2222
const logger = new InternalLogger({
2323
logLevel: getLogLevel(cfg?.application?.logLevel),
2424
mongoose: cfg?.mongoose,
25-
});
26-
await logger.initialize();
25+
})
26+
await logger.initialize()
2727

28-
let extraOptions = <any>{};
28+
let extraOptions = <any>{}
2929
if (cfg.application?.https?.enabled) {
3030
try {
3131
extraOptions.httpsOptions = {
3232
key: readFileSync(cfg.application?.https?.key),
3333
cert: readFileSync(cfg.application?.https?.cert),
3434
};
35-
logger.log('HTTPS is enabled !');
35+
logger.log('HTTPS is enabled !')
3636
} catch (error) {
37-
logger.error('Error while reading https key and cert', error);
37+
logger.error('Error while reading https key and cert', error)
3838
}
3939
}
4040

41-
const server = express();
41+
const server = express()
4242
const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(server), {
4343
snapshot: true,
4444
bodyParser: false,
4545
rawBody: true,
4646
cors: true,
4747
logger,
4848
...extraOptions,
49-
});
49+
})
5050
app.use((_: any, res: Response, next: () => void) => {
5151
res.removeHeader('x-powered-by');
5252
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())
5757
if (process.env.production !== 'production') {
58-
await (await import('./swagger')).default(app);
58+
await (await import('./swagger')).default(app)
5959
}
6060

61-
useContainer(app.select(AppModule), { fallbackOnErrors: true });
61+
useContainer(app.select(AppModule), { fallbackOnErrors: true })
6262

63-
await app.init();
63+
await app.init()
6464

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)
6767

6868
// 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
7272

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> !`)
7575

7676
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)
7878

7979
// 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
8383

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> !`)
8686
}
8787

8888
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())
9191
}
9292
})();

apps/api/src/swagger.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// import { Logger } from '@nestjs/common';
2-
import { ConfigService } from '@nestjs/config';
3-
import { NestExpressApplication } from '@nestjs/platform-express';
4-
import { DocumentBuilder, SwaggerCustomOptions, SwaggerModule } from '@nestjs/swagger';
5-
import { Response } from 'express';
6-
import { readFileSync } from 'fs';
7-
// import { RedocModule } from 'nestjs-redoc';
8-
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes';
1+
import { ConfigService } from '@nestjs/config'
2+
import { NestExpressApplication } from '@nestjs/platform-express'
3+
import { DocumentBuilder, SwaggerCustomOptions, SwaggerModule } from '@nestjs/swagger'
4+
import { Response } from 'express'
5+
import { readFileSync } from 'fs'
6+
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes'
97

108
export default async function swagger(app: NestExpressApplication) {
11-
const config = app.get<ConfigService>(ConfigService);
12-
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
9+
const config = app.get<ConfigService>(ConfigService)
10+
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'))
1311

1412
const build = new DocumentBuilder()
1513
.setTitle(pkg.name)
@@ -18,10 +16,10 @@ export default async function swagger(app: NestExpressApplication) {
1816
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'jwt')
1917
.addSecurityRequirements('jwt')
2018

21-
.build();
19+
.build()
2220

23-
const document = SwaggerModule.createDocument(app, build);
24-
const theme = new SwaggerTheme();
21+
const document = SwaggerModule.createDocument(app, build)
22+
const theme = new SwaggerTheme()
2523

2624
SwaggerModule.setup(config.get<string>('swagger.path'), app, document, {
2725
...config.get<SwaggerCustomOptions>('swagger.options'),
@@ -31,7 +29,7 @@ export default async function swagger(app: NestExpressApplication) {
3129
persistAuthorization: true,
3230
},
3331
customCss: theme.getBuffer(SwaggerThemeNameEnum.ONE_DARK),
34-
});
32+
})
3533

36-
app.getHttpAdapter().get(config.get<string>('swagger.api'), (_, res: Response) => res.json(document));
34+
app.getHttpAdapter().get(config.get<string>('swagger.api'), (_, res: Response) => res.json(document))
3735
}

0 commit comments

Comments
 (0)