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);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ Edit `.env.prod`. Mandatory configuration:
|
||||
| `POSTGRES_MIGRATIONS_RUN` | `true` |
|
||||
| `PGADMIN_DEFAULT_PASSWORD` | strong random password |
|
||||
| `NODE_ENV` | `production` |
|
||||
| `CORS_ORIGINS` | `https://your-domain.com` |
|
||||
| `CLEARNET_DOMAIN` | `your-domain.com` |
|
||||
| `JWT_SECRET` | strong random secret |
|
||||
| `CMS_PASSWORD` | strong admin password |
|
||||
|
||||
Reference in New Issue
Block a user