From 4341f8d2c6355b6b778fb408cecb025d1b8c52e0 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@ip-172-31-1-27.ap-northeast-2.compute.internal> Date: Wed, 4 Dec 2024 05:38:10 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=ED=95=9C=20=EC=84=B8=EC=85=98=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 41 ++++++++++++++++++++++++++++++----------- output.log | 19 +++++++++++++++++-- routes/auth.js | 2 +- weblog.log | 42 +++++++++++++++++++++--------------------- 4 files changed, 69 insertions(+), 35 deletions(-) diff --git a/app.js b/app.js index b749726..8fb70a5 100644 --- a/app.js +++ b/app.js @@ -17,14 +17,33 @@ const app = express(); app.use(morgan('dev')); //濡쒓퉭�� // CORS �ㅼ젙 -app.use( - cors({ - origin: process.env.FRONTEND_URL, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], - allowedHeaders: ['Content-Type', 'Authorization'], - credentials: true, - }) -); + +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( session({ @@ -36,7 +55,7 @@ app.use( httpOnly: true, secure: false, maxAge: 60 * 60 * 1000, // 1�쒓컙 - sameSite: 'lax', + sameSite: 'raw', }, }) ); @@ -55,7 +74,7 @@ app.use(flash()); console.log('MongoDB URI:', process.env.MONGO_URI); //�쇱슦�� �깅줉 const authRoutes = require('./routes/auth'); -app.use('/auth', authRoutes); +app.use('/api/auth',authRoutes); const scheduleRoutes = require('./routes/schedule'); app.use('/api/schedule', scheduleRoutes); @@ -92,4 +111,4 @@ const PORT = process.env.PORT || 3000; console.error('�� �쒕쾭 �쒖옉 以� �ㅻ쪟 諛쒖깮:', error); process.exit(1); } -})(); \ No newline at end of file +})(); diff --git a/output.log b/output.log index 819b52d..18efc16 100644 --- a/output.log +++ b/output.log @@ -1,8 +1,23 @@ MongoDB URI: mongodb+srv://admin:lim1234!!@goodmeeting.vkniz.mongodb.net/ -(node:44244) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:4343) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version (Use `node --trace-warnings ...` to show where the warning was created) -(node:44244) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:4343) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version �� MongoDB �곌껐 �깃났 Rdb�곗씠�곕쿋�댁뒪 �곌껐 �깃났. 紐⑤뱺 紐⑤뜽�� �깃났�곸쑝濡� �숆린�붾릺�덉뒿�덈떎. Server is running on 8080 +CORS Origin: undefined +[0mGET /api/auth/login [36m302[0m 7.657 ms - 0[0m +TypeError: option sameSite is invalid + at Object.serialize (/home/ubuntu/webback/node_modules/express-session/node_modules/cookie/index.js:290:15) + at setcookie (/home/ubuntu/webback/node_modules/express-session/index.js:665:21) + at ServerResponse.<anonymous> (/home/ubuntu/webback/node_modules/express-session/index.js:248:9) + at ServerResponse.writeHead (/home/ubuntu/webback/node_modules/on-headers/index.js:35:16) + at ServerResponse._implicitHeader (node:_http_server:338:8) + at writetop (/home/ubuntu/webback/node_modules/express-session/index.js:284:15) + at ServerResponse.end (/home/ubuntu/webback/node_modules/express-session/index.js:351:16) + at strategy.redirect (/home/ubuntu/webback/node_modules/passport/lib/middleware/authenticate.js:342:13) + at stored (/home/ubuntu/webback/node_modules/passport-oauth2/lib/strategy.js:285:14) + at NullStore.store (/home/ubuntu/webback/node_modules/passport-oauth2/lib/state/null.js:5:3) +CORS Origin: undefined +[0mGET /api/schedule/all [33m401[0m 3.524 ms - 44[0m diff --git a/routes/auth.js b/routes/auth.js index 9e2c4c3..fcf2d3e 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -3,7 +3,7 @@ const passport = require('passport'); const router = express.Router(); -// GET /auth/login +// GET api/auth/login router.get('/login', (req, res, next) => { // �꾨줎�몄뿏�쒖뿉�� �꾨떖�� redirectUrl 媛��몄삤湲� const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; diff --git a/weblog.log b/weblog.log index 2ac6636..38198c5 100644 --- a/weblog.log +++ b/weblog.log @@ -1,22 +1,22 @@ -node:internal/modules/cjs/loader:1143 - throw err; - ^ - -Error: Cannot find module './resources/firebase/yanawa-89d9d-firebase-adminsdk-d1inm-24566bf0b9.json' -Require stack: -- /home/ubuntu/webback/wsServer.js - at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15) - at Module._load (node:internal/modules/cjs/loader:981:27) - at Module.require (node:internal/modules/cjs/loader:1231:19) - at require (node:internal/modules/helpers:177:18) - at Object.<anonymous> (/home/ubuntu/webback/wsServer.js:18:37) - at Module._compile (node:internal/modules/cjs/loader:1364:14) - at Module._extensions..js (node:internal/modules/cjs/loader:1422:10) - at Module.load (node:internal/modules/cjs/loader:1203:32) - at Module._load (node:internal/modules/cjs/loader:1019:12) - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) { - code: 'MODULE_NOT_FOUND', - requireStack: [ '/home/ubuntu/webback/wsServer.js' ] +(node:4344) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(Use `node --trace-warnings ...` to show where the warning was created) +(node:4344) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +MongoDB �곌껐 �ㅽ뙣: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 + at _handleConnectionErrors (/home/ubuntu/webback/node_modules/mongoose/lib/connection.js:909:11) + at NativeConnection.openUri (/home/ubuntu/webback/node_modules/mongoose/lib/connection.js:860:11) + at async connectMongoDB (/home/ubuntu/webback/wsServer.js:28:5) { + reason: TopologyDescription { + type: 'Unknown', + servers: Map(1) { 'localhost:27017' => [ServerDescription] }, + stale: false, + compatible: true, + heartbeatFrequencyMS: 10000, + localThresholdMS: 15, + setName: null, + maxElectionId: null, + maxSetVersion: null, + commonWireVersion: 0, + logicalSessionTimeoutMinutes: null + }, + code: undefined } - -Node.js v18.20.5 -- GitLab