-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change allowed origins from env variables
- Loading branch information
1 parent
c62d1cf
commit e8028b7
Showing
4 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ NODE_ENV= | |
|
||
PORT= | ||
|
||
ALLOWED_ORIGIN=r34.app | ||
|
||
JWT_SECRET= | ||
JWT_EXPIRATION_TIME=30m | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 +1,49 @@ | ||
import { ValidationPipe } from '@nestjs/common' | ||
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface' | ||
import { NestFactory } from '@nestjs/core' | ||
import { ConfigService } from '@nestjs/config' | ||
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify' | ||
import {ValidationPipe} from '@nestjs/common' | ||
import {CorsOptions} from '@nestjs/common/interfaces/external/cors-options.interface' | ||
import {NestFactory} from '@nestjs/core' | ||
import {ConfigService} from '@nestjs/config' | ||
import {FastifyAdapter, NestFastifyApplication} from '@nestjs/platform-fastify' | ||
import helmet from '@fastify/helmet' | ||
import * as Sentry from '@sentry/node' | ||
import { AppModule } from './app.module' | ||
import {AppModule} from './app.module' | ||
import {escapeRegExp} from 'lodash' | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter()) | ||
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter()) | ||
|
||
const configService: ConfigService = app.get(ConfigService) | ||
const configService: ConfigService = app.get(ConfigService) | ||
|
||
// Sentry | ||
Sentry.init({ | ||
enabled: configService.get<boolean>('SENTRY_ENABLED') || false, | ||
dsn: configService.get<string>('SENTRY_DSN') | ||
// Sentry | ||
Sentry.init({ | ||
enabled: configService.get<boolean>('SENTRY_ENABLED') || false, | ||
dsn: configService.get<string>('SENTRY_DSN') | ||
|
||
// ignoreErrors: ['NoContentException', 'MethodNotAllowedException'], | ||
}) | ||
// ignoreErrors: ['NoContentException', 'MethodNotAllowedException'], | ||
}) | ||
|
||
app.register(helmet) | ||
app.register(helmet) | ||
|
||
const corsOptions: CorsOptions = { | ||
origin: configService.get<string>('NODE_ENV') === 'development' ? true : /r34\.app$/, | ||
credentials: true | ||
} | ||
const allowedOrigin = configService.get<string>('ALLOWED_ORIGIN') | ||
const allowedOriginRegex = new RegExp(escapeRegExp(allowedOrigin) + '$') | ||
|
||
app.enableCors(corsOptions) | ||
const corsOptions: CorsOptions = { | ||
origin: configService.get<string>('NODE_ENV') === 'development' ? true : allowedOriginRegex, | ||
credentials: true | ||
} | ||
|
||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, // Transform to DTO type | ||
// transformOptions: { enableImplicitConversion: true }, | ||
app.enableCors(corsOptions) | ||
|
||
whitelist: true, // Remove unnecessary properties | ||
forbidNonWhitelisted: true // Sends "property <property> should not exist." error | ||
}) | ||
) | ||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, // Transform to DTO type | ||
// transformOptions: { enableImplicitConversion: true }, | ||
|
||
whitelist: true, // Remove unnecessary properties | ||
forbidNonWhitelisted: true // Sends "property <property> should not exist." error | ||
}) | ||
) | ||
|
||
await app.listen(configService.get<number>('PORT'), '0.0.0.0') | ||
await app.listen(configService.get<number>('PORT'), '0.0.0.0') | ||
} | ||
|
||
bootstrap() |