Skip to content

Commit

Permalink
feat(backend): setup helmet
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Feb 7, 2024
1 parent 5992631 commit 987132c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
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
5 changes: 5 additions & 0 deletions luna-backend/src/infrastructure/utils/modules/modules.d.ts
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;
}
34 changes: 33 additions & 1 deletion luna-backend/src/main.ts
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();

0 comments on commit 987132c

Please sign in to comment.