Skip to content

Commit dc1f17d

Browse files
committed
fix: API 응답 및 에러 처리 방식 개선
- API 응답이 404인 경우 원본 HTML을 반환하여 클라이언트 라우팅이 처리하도록 수정 - 에러 발생 시에도 원본 HTML을 반환하여 클라이언트 라우팅이 처리하도록 변경
1 parent fc9d754 commit dc1f17d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

apps/web/middleware.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ export default async function middleware(request: Request) {
1818
);
1919

2020
if (!response.ok) {
21-
// API 응답이 404인 경우 클라이언트 라우팅으로 처리
22-
return new Response(null, {
21+
// API 응답이 404인 경우 원본 HTML을 반환하여 클라이언트 라우팅이 처리하도록 함
22+
const res = await fetch(new URL('/', request.url));
23+
const html = await res.text();
24+
return new Response(html, {
2325
status: 200,
26+
headers: {
27+
'content-type': 'text/html;charset=UTF-8',
28+
},
2429
});
2530
}
2631

@@ -71,9 +76,14 @@ export default async function middleware(request: Request) {
7176
},
7277
});
7378
} catch (error) {
74-
// 에러 발생 시 클라이언트 라우팅으로 처리
75-
return new Response(null, {
79+
// 에러 발생 시 원본 HTML을 반환하여 클라이언트 라우팅이 처리하도록 함
80+
const res = await fetch(new URL('/', request.url));
81+
const html = await res.text();
82+
return new Response(html, {
7683
status: 200,
84+
headers: {
85+
'content-type': 'text/html;charset=UTF-8',
86+
},
7787
});
7888
}
7989
}

0 commit comments

Comments
 (0)