Refactor CORS configuration and add utility, update package.json for dev start command, and create GraphQL query/mutation files

This commit is contained in:
2024-10-06 12:36:15 +07:00
parent 121396aa8f
commit 67f6e7cc57
9 changed files with 14 additions and 10 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"dependi.npm.lockFileEnabled": false
}

View File

@@ -9,7 +9,7 @@
"build": "nest build", "build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start", "start": "nest start",
"start:dev": "nest start --watch", "start:dev": "npm run prisma:generate && nest start --watch",
"start:debug": "nest start --debug --watch", "start:debug": "nest start --debug --watch",
"start:prod": "node dist/main", "start:prod": "node dist/main",
"prisma:generate": "npx prisma generate --schema=./epess-database/prisma/schema.prisma", "prisma:generate": "npx prisma generate --schema=./epess-database/prisma/schema.prisma",

View File

@@ -0,0 +1,6 @@
export const cors = {
origin: process.env.CORS_ORIGIN,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true,
};

View File

View File

View File

@@ -1,15 +1,10 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { cors } from './common/utils/cors.utils';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
app.enableCors({ app.enableCors(cors);
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
});
await app.listen(3000); await app.listen(3000);
} }
bootstrap(); bootstrap();