File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,27 @@ let items = null;
1010// 상품 데이터 로드 (서버에서는 동기적으로)
1111function loadItems ( ) {
1212 if ( ! items ) {
13- const itemsPath = path . join ( __dirname , "../mocks/items.json" ) ;
14- items = JSON . parse ( fs . readFileSync ( itemsPath , "utf-8" ) ) ;
13+ // 빌드 환경에서도 작동하도록 절대 경로 사용
14+ let itemsPath ;
15+ try {
16+ // 개발 환경: src/api/mockApi.js에서 실행
17+ itemsPath = path . join ( __dirname , "../mocks/items.json" ) ;
18+ items = JSON . parse ( fs . readFileSync ( itemsPath , "utf-8" ) ) ;
19+ } catch ( error ) {
20+ console . error ( error . message ) ;
21+ try {
22+ // 빌드 환경: dist/vanilla-ssr/main-server.js에서 실행
23+ // 프로젝트 루트/packages/vanilla/src/mocks/items.json을 찾기
24+ const currentDir = process . cwd ( ) ;
25+ itemsPath = path . join ( currentDir , "src/mocks/items.json" ) ;
26+ items = JSON . parse ( fs . readFileSync ( itemsPath , "utf-8" ) ) ;
27+ } catch ( buildError ) {
28+ // 최후 수단: 상대 경로로 시도
29+ itemsPath = path . resolve ( __dirname , "../../src/mocks/items.json" ) ;
30+ items = JSON . parse ( fs . readFileSync ( itemsPath , "utf-8" ) ) ;
31+ console . error ( buildError . message ) ;
32+ }
33+ }
1534 }
1635 return items ;
1736}
You can’t perform that action at this time.
0 commit comments