Skip to content

Commit

Permalink
fix: nginx와 nextjs 간 origin 설정 충돌로 인한 cors 에러 수정 (#160)
Browse files Browse the repository at this point in the history
fix: nginx와 nextjs 간 origin 설정 충돌로 인한 cors 에러 수정
  • Loading branch information
heegenie authored Nov 27, 2024
1 parent 75eef31 commit 0e1ec50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
25 changes: 17 additions & 8 deletions packages/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger, VersioningType } from '@nestjs/common';
import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { IoAdapter } from '@nestjs/platform-socket.io';
import { WsAdapter } from '@nestjs/platform-ws';
import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

Expand All @@ -23,14 +24,22 @@ function configureGlobalSettings(app: any) {
app.useGlobalFilters(new AllExceptionsFilter());
app.useWebSocketAdapter(new WsAdapter(app));
app.enableCors({
origin: [
'http://www.honeyflow.life',
'https://www.honeyflow.life',
'http://localhost',
'http://localhost:5173',
],
origin: (origin, callback) => {
const allowedOrigins = [
'http://www.honeyflow.life',
'https://www.honeyflow.life',
'http://localhost',
'http://localhost:5173',
];
if (!origin || allowedOrigins.includes(origin)) {
callback(null, origin);
} else {
callback(new Error('Not allowed by CORS'));
}
},
methods: 'GET, POST, PUT, DELETE',
allowedHeaders: 'Content-Type, Authorization',
credentials: true,
});
app.enableVersioning({
type: VersioningType.URI,
Expand Down
11 changes: 5 additions & 6 deletions packages/frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept, Authorization';
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept, Authorization';
}
# Backend Socket 설정
location /ws/ {
Expand All @@ -45,9 +44,9 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept, Authorization';
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept, Authorization';
}

location /kibana/ {
Expand Down

0 comments on commit 0e1ec50

Please sign in to comment.