Skip to content

Commit 079b860

Browse files
committed
Fix absolute paths for JSON data fetching
1 parent 51f4a38 commit 079b860

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

client/src/pages/Home.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ export default function Home() {
2424
}, 100);
2525
}
2626

27-
const logicTreeFile = '/data/logicTrees.json';
27+
const basePath = import.meta.env.BASE_URL;
28+
const prefix = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
29+
30+
const logicTreeFile = `${prefix}/data/logicTrees.json`;
2831
Promise.all([
2932
fetch(logicTreeFile).then(res => res.json()),
30-
fetch('/data/urlMap.json').then(res => res.json())
33+
fetch(`${prefix}/data/urlMap.json`).then(res => res.json())
3134
])
3235
.then(([data, map]) => {
3336
if (data && data.LOGIC_TREES) {

client/src/pages/Quiz.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export default function Quiz() {
1818

1919
// 1. Fetch Data (Static JSONs)
2020
useEffect(() => {
21+
const basePath = import.meta.env.BASE_URL;
22+
const prefix = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
23+
2124
// ALWAYS fetch the main logicTrees.json, which now contains keys.
2225
// The text content is in the locale files loaded by LanguageContext.
23-
const logicTreeFile = '/data/logicTrees.json';
26+
const logicTreeFile = `${prefix}/data/logicTrees.json`;
2427

2528
Promise.all([
2629
fetch(logicTreeFile).then(res => res.json()),
27-
fetch('/data/urlMap.json').then(res => res.json())
30+
fetch(`${prefix}/data/urlMap.json`).then(res => res.json())
2831
])
2932
.then(([logic, map]) => {
3033
setLogicData(logic);

0 commit comments

Comments
 (0)