diff --git a/app.js b/app.js index b749726aca097bb0d4ea1ea7de173fbc42a93da1..04fcb7789a21aa9ddd5596867c2f5bfd6e0cbc48 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({ @@ -34,9 +53,9 @@ app.use( rolling: true, cookie: { httpOnly: true, - secure: false, + secure: true, maxAge: 60 * 60 * 1000, // 1�쒓컙 - sameSite: 'lax', + sameSite: 'none', }, }) ); @@ -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 819b52d215874f85b04db61021421ebce210f6c7..14b3255d00c51a2da75cd7010b220d1d3178280c 100644 --- a/output.log +++ b/output.log @@ -1,8 +1,14 @@ 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:4550) [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:4550) [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.628 ms - 0[0m +CORS Origin: undefined +[0mGET /api/schedule/all [33m401[0m 3.639 ms - 44[0m +CORS Origin: undefined +[0mGET /api/schedule/all [33m401[0m 1.347 ms - 44[0m diff --git a/routes/auth.js b/routes/auth.js index 9e2c4c36ef6a693db7525cd39157a3a694adb43b..fcf2d3ef8adf83432ddf812fe402ce1c83e0a9b2 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 2ac6636d8e84aa62e66d37d5dc3cf29688bbfc9a..20d81735058d1cf5007c4aad0ea514fac26e7149 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:4551) [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:4551) [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