Enable CORS only in development.
Production serves the CMS and API on one origin, so the allowlist is only needed while they run on separate ports.
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsString, Max, Min, validateSync } from 'class-validator';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsString,
|
||||
Max,
|
||||
Min,
|
||||
ValidateIf,
|
||||
validateSync
|
||||
} from 'class-validator';
|
||||
import { NodeEnv } from '../types/NodeEnv';
|
||||
import { ShopFiatCurrency } from '../types/ShopFiatCurrency';
|
||||
import { IsBase64 } from '../validation/decorators/isBase64';
|
||||
@@ -41,6 +51,7 @@ class EnvironmentVariables {
|
||||
@IsBoolean()
|
||||
POSTGRES_MIGRATIONS_RUN: boolean;
|
||||
|
||||
@ValidateIf((config: EnvironmentVariables) => config.NODE_ENV === NodeEnv.Development)
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
CORS_ORIGINS: string;
|
||||
|
||||
+6
-4
@@ -106,10 +106,12 @@ async function bootstrap() {
|
||||
]
|
||||
});
|
||||
|
||||
app.enableCors({
|
||||
origin: corsOrigins,
|
||||
credentials: true
|
||||
});
|
||||
if (nodeEnv === NodeEnv.Development) {
|
||||
app.enableCors({
|
||||
origin: corsOrigins,
|
||||
credentials: true
|
||||
});
|
||||
}
|
||||
|
||||
await app.listen(port);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user