From 813eb395d9f2bd7b9a95c2ea3fe5ddf1a6e9d7cc 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 08:21:38 +0000
Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9D=EC=8B=9C?=
 =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B0=8F=20https=20=EC=BF=A0=ED=82=A4?=
 =?UTF-8?q?=EC=84=A4=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.js                     | 38 ++++++++++++--------------------------
 output.log                 | 10 ++--------
 passport/googleStrategy.js |  1 -
 routes/auth.js             | 26 ++++++++++++--------------
 weblog.log                 |  4 ++--
 5 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/app.js b/app.js
index 04fcb77..4156dea 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 14b3255..15aceb8 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
-GET /api/auth/login 302 7.628 ms - 0
-CORS Origin: undefined
-GET /api/schedule/all 401 3.639 ms - 44
-CORS Origin: undefined
-GET /api/schedule/all 401 1.347 ms - 44
diff --git a/passport/googleStrategy.js b/passport/googleStrategy.js
index ada1aef..6926dee 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 fcf2d3e..576d376 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 20d8173..e05bb44 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)
-- 
GitLab