From 1b9c733671c20f70ecbedf99aff6bb3e91d46be0 Mon Sep 17 00:00:00 2001 From: tpgus2603 <kakaneymar2424@gmail.com> Date: Wed, 4 Dec 2024 14:46:39 +0900 Subject: [PATCH] =?UTF-8?q?jwt=EA=B8=B0=EB=B0=98=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=9D=B8=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index 04fcb77..bf2bd1d 100644 --- a/app.js +++ b/app.js @@ -17,33 +17,14 @@ const app = express(); app.use(morgan('dev')); //濡쒓퉭�� // CORS �ㅼ젙 - -const corsOptions = { - origin: (origin, callback) => { - console.log('CORS Origin:', origin); // �붾쾭源낆슜 濡쒓렇 - const allowedOrigins = [ - 'http://localhost:3000', // 濡쒖뺄 媛쒕컻 �섍꼍 - 'http://ec2-43-203-68-83.ap-northeast-2.compute.amazonaws.com', // EC2 諛깆뿏�� - ]; - if (!origin) return callback(null, true); // origin�� �놁쑝硫� �덉슜 (e.g., Postman) - if (allowedOrigins.includes(origin)) { - return callback(null, true); - } - console.log('CORS origin rejected:', origin); // 李⑤떒�� origin 濡쒓렇 - return callback(new Error('Not allowed by CORS')); - }, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], - allowedHeaders: ['Content-Type', 'Authorization'], - credentials: true, // 荑좏궎 �덉슜 -}; - -// CORS 誘몃뱾�⑥뼱 �곸슜 -app.use(cors(corsOptions)); - -// Preflight �붿껌 泥섎━ -app.options('*', cors(corsOptions)); - - +app.use( + cors({ + origin: process.env.FRONTEND_URL, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization'], + credentials: true, + }) +); // app.use( session({ @@ -74,7 +55,7 @@ app.use(flash()); console.log('MongoDB URI:', process.env.MONGO_URI); //�쇱슦�� �깅줉 const authRoutes = require('./routes/auth'); -app.use('/api/auth',authRoutes); +app.use('/auth', authRoutes); const scheduleRoutes = require('./routes/schedule'); app.use('/api/schedule', scheduleRoutes); @@ -111,4 +92,4 @@ const PORT = process.env.PORT || 3000; console.error('�� �쒕쾭 �쒖옉 以� �ㅻ쪟 諛쒖깮:', error); process.exit(1); } -})(); +})(); \ No newline at end of file -- GitLab