Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Commits
1b9c7336
Commit
1b9c7336
authored
3 months ago
by
tpgus2603
Browse files
Options
Downloads
Patches
Plain Diff
jwt기반 로그인인증
parent
e0ea0904
No related branches found
Branches containing commit
No related tags found
1 merge request
!42
[#25] 배포코드 master브랜치로 이동
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.js
+10
-29
10 additions, 29 deletions
app.js
with
10 additions
and
29 deletions
app.js
+
10
−
29
View file @
1b9c7336
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment