Skip to content

Commit

Permalink
cors settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hero101 committed Jun 24, 2024
1 parent 0f721ad commit d5ed2c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"homepage": "https://github.com/alkem-io/file-service#readme",
"dependencies": {
"@fastify/cookie": "^9.3.1",
"@fastify/cors": "^9.0.1",
"@fastify/helmet": "^11.1.1",
"@nestjs/common": "^10.3.8",
"@nestjs/config": "^3.2.2",
Expand Down
14 changes: 3 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { ConfigService } from '@nestjs/config';
import helmet from '@fastify/helmet';
import fastifyCookie from '@fastify/cookie';
import { ConfigService } from '@nestjs/config';
import cors from '@fastify/cors';
import { AppModule } from './app.module';
import { ConfigType } from './config';

Expand All @@ -29,18 +30,9 @@ const isProd = process.env.NODE_ENV === 'production';
const logger = app.get(WINSTON_MODULE_NEST_PROVIDER);
app.useLogger(logger);

app.enableCors({
origin: '*',
allowedHeaders: [
'Origin,X-Requested-With',
'Content-Type,Accept',
'Authorization',
],
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
});

await app.register(fastifyCookie);
await app.register(helmet, { contentSecurityPolicy: false });
await app.register(cors, { origin: false });

const configService: ConfigService<ConfigType, true> = app.get(ConfigService);
const port = configService.get('settings.application.port', { infer: true });
Expand Down

0 comments on commit d5ed2c0

Please sign in to comment.