-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
luna-backend/src/infrastructure/utils/modules/helmet/modules.helmet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import inclusion from 'inclusion'; | ||
|
||
// START helmet module | ||
import type Helmet from 'helmet'; | ||
|
||
type IHelmet = typeof Helmet; | ||
|
||
export const getModuleHelmet = (): Promise<IHelmet> => | ||
inclusion('helmet').then((mod) => mod.default); | ||
|
||
// END helmet module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module 'inclusion' { | ||
function inclusion(moduleName: string): Promise<any>; | ||
|
||
export = inclusion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import compression from 'compression'; | ||
import { AppModule } from './application/root/app.module'; | ||
import { EnvironmentConfigService } from './infrastructure/environment-config'; | ||
import { getModuleHelmet } from './infrastructure/utils/modules/helmet/modules.helmet'; | ||
|
||
async function bootstrap() { | ||
// | ||
|
||
const app = await NestFactory.create(AppModule); | ||
await app.listen(3000); | ||
|
||
const environmentConfigService = app.get(EnvironmentConfigService); | ||
|
||
// | ||
|
||
const isProduction = environmentConfigService.getRuntimeIsProduction(); | ||
|
||
// | ||
|
||
const helmet = await getModuleHelmet(); | ||
|
||
app.use( | ||
helmet({ | ||
contentSecurityPolicy: isProduction ? undefined : false, | ||
crossOriginEmbedderPolicy: false, | ||
}), | ||
); | ||
|
||
// | ||
|
||
app.use(compression()); | ||
|
||
// | ||
|
||
const port = environmentConfigService.getRuntimePort(); | ||
|
||
await app.listen(port); | ||
} | ||
|
||
bootstrap(); |