Skip to content

Commit f14966b

Browse files
committed
[FE] Refactor : CORS 코드 수정
- CORS 미들웨어에 config를 사용하여 origin 명시 - 요청 헤더에 필요없는 헤더들 삭제 (서버단에서 CORS 처리 해줬으므로)
1 parent 24330d3 commit f14966b

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

backend/src/app.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ const startApp = async (): Promise<void> => {
4343
app.use(bodyParser.json());
4444
app.use(bodyParser.urlencoded({ extended: false }));
4545
app.use(morgan('dev'));
46-
// TODO: 허용할 주소 정확히 명시하기
47-
app.use(cors());
46+
47+
const options = {
48+
origin: process.env.SERVICE_URL,
49+
credentials: true,
50+
};
51+
52+
app.use(cors(options));
53+
4854
app.use(passport.initialize());
4955
passportConfig();
5056

frontend/src/api/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import axios from 'axios';
22

33
const api = axios.create({
44
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
5-
headers: {
6-
// 'Access-Control-Allow-Origin': '*',
7-
'Access-Control-Allow-Credentials': 'true',
8-
'Access-Control-Allow-Methods': 'GET, POST, PATCH, DELETE, PUT, OPTIONS',
9-
'Access-Control-Allow-Headers':
10-
'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With',
11-
},
125
validateStatus(status) {
136
return status < 500;
147
},

frontend/src/hooks/useFetch.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ const useFetch = (url, token) => {
44
const options = {
55
method: 'GET',
66
headers: {
7-
Accept: 'application/json',
8-
'Content-Type': 'application/json;charset=UTF-8',
97
Authorization: token,
108
},
11-
credentails: 'true',
129
};
1310
const fetcher = endpoint =>
1411
fetch(process.env.NEXT_PUBLIC_API_BASE_URL + endpoint, options).then(res => res.json());

settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"editor.formatOnSave": false,
2+
"editor.formatOnSave": true,
33
"editor.codeActionsOnSave": {
44
"source.fixAll.eslint": true
55
}
6-
}
6+
}

0 commit comments

Comments
 (0)