fix api products
This commit is contained in:
@@ -2,7 +2,7 @@ export default () => ({
|
||||
app: {
|
||||
port: parseInt(process.env.PORT ?? '3000', 10),
|
||||
nodeEnv: process.env.NODE_ENV ?? 'development',
|
||||
corsOrigins: (process.env.CORS_ORIGINS ?? 'http://localhost:3000')
|
||||
corsOrigins: (process.env.CORS_ORIGINS ?? '*')
|
||||
.split(',')
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean),
|
||||
|
||||
21
src/main.ts
21
src/main.ts
@@ -11,13 +11,30 @@ async function bootstrap() {
|
||||
const reflector = app.get(Reflector);
|
||||
const configService = app.get(ConfigService);
|
||||
const corsOrigins = configService.get<string[]>('app.corsOrigins', []);
|
||||
const allowAllOrigins = corsOrigins.includes('*');
|
||||
|
||||
app.setGlobalPrefix('api');
|
||||
app.enableCors({
|
||||
origin: corsOrigins,
|
||||
origin: (origin, callback) => {
|
||||
if (!origin || allowAllOrigins || corsOrigins.includes(origin)) {
|
||||
callback(null, true);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(new Error(`Origin ${origin} is not allowed by CORS`), false);
|
||||
},
|
||||
credentials: true,
|
||||
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization', 'x-product-type'],
|
||||
allowedHeaders: [
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
'x-product-type',
|
||||
'Accept',
|
||||
'Origin',
|
||||
'X-Requested-With',
|
||||
],
|
||||
exposedHeaders: ['Content-Disposition'],
|
||||
optionsSuccessStatus: 204,
|
||||
});
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
|
||||
Reference in New Issue
Block a user