diff --git a/app.js b/app.js index 04fcb7789a21aa9ddd5596867c2f5bfd6e0cbc48..4156deafcdef3095499d0217b3f0fe9bbf76a6dd 100644 --- a/app.js +++ b/app.js @@ -18,32 +18,16 @@ 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)); - +// CORS �ㅼ젙 +app.use( + cors({ + origin: 'https://yanawa.shop', + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization'], + credentials: true, + }) +); // app.use( session({ @@ -60,7 +44,6 @@ app.use( }) ); - // 誘몃뱾�⑥뼱 �ㅼ젙 app.use(express.json()); app.use(express.urlencoded({ extended: false })); @@ -71,6 +54,9 @@ app.use(passport.session()); app.use(flash()); + + +app.set('trust proxy', 1); console.log('MongoDB URI:', process.env.MONGO_URI); //�쇱슦�� �깅줉 const authRoutes = require('./routes/auth'); diff --git a/output.log b/output.log index 14b3255d00c51a2da75cd7010b220d1d3178280c..15aceb8ded67ed7dc18ad9477acfbcf4e5118284 100644 --- a/output.log +++ b/output.log @@ -1,14 +1,8 @@ MongoDB URI: mongodb+srv://admin:lim1234!!@goodmeeting.vkniz.mongodb.net/ -(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 +(node:8604) [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: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 +(node:8604) [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/passport/googleStrategy.js b/passport/googleStrategy.js index ada1aef6fa1cdeea29147c2e039625cae2b22424..6926deeb8ef2f6809d99e1f11b264a2ba08d9959 100644 --- a/passport/googleStrategy.js +++ b/passport/googleStrategy.js @@ -7,7 +7,6 @@ module.exports = new GoogleStrategy( clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: process.env.CALLBACK_URL, - passReqToCallback: true, // req 媛앹껜瑜� 肄쒕갚�� �꾨떖 }, async (req, accessToken, refreshToken, profile, done) => { try { diff --git a/routes/auth.js b/routes/auth.js index fcf2d3ef8adf83432ddf812fe402ce1c83e0a9b2..576d37640e0fb0dd39183af4cd9c9a4b5ae7c8c5 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -6,13 +6,8 @@ const router = express.Router(); // GET api/auth/login router.get('/login', (req, res, next) => { // �꾨줎�몄뿏�쒖뿉�� �꾨떖�� redirectUrl 媛��몄삤湲� - const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; - - // redirectUrl �좏슚�� 寃�利� - const allowedDomains = [process.env.FRONTEND_URL || 'http://localhost:3000']; - if (!allowedDomains.some((domain) => redirectUrl.startsWith(domain))) { - return res.status(400).json({ error: 'Invalid redirect URL' }); - } + const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'https://yanawa.shop'; + // redirectUrl �좏슚�� 寃�利� // redirectUrl �몄뀡�� ���� req.session.redirectUrl = redirectUrl; @@ -20,20 +15,23 @@ router.get('/login', (req, res, next) => { // Google OAuth �몄쬆 �쒖옉 passport.authenticate('google', { scope: ['profile', 'email'] })(req, res, next); }); - -// GET /auth/google/callback router.get( '/google/callback', passport.authenticate('google', { failureRedirect: '/auth/login' }), (req, res) => { - // �몄뀡�먯꽌 redirectUrl 媛��몄삤湲� - const redirectUrl = req.session.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; + const redirectUrl = req.session.redirectUrl || 'https://yanawa.shop'; + - // �몄뀡�먯꽌 redirectUrl �쒓굅 req.session.redirectUrl = null; - // �몄쬆 �꾨즺 �� �꾨줎�몄뿏�쒕줈 由щ떎�대젆�� - res.redirect(redirectUrl); + req.session.save((err) => { + if (err) { + console.error('�몄뀡 ���� �ㅻ쪟:', err); + return res.status(500).json({ error: '�쒕쾭 �ㅻ쪟' }); + } + + res.redirect(redirectUrl); + }); } ); diff --git a/weblog.log b/weblog.log index 20d81735058d1cf5007c4aad0ea514fac26e7149..e05bb44904ad4d240166b65c52c8c282a2cb5cc1 100644 --- a/weblog.log +++ b/weblog.log @@ -1,6 +1,6 @@ -(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 +(node:8605) [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 +(node:8605) [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)