Skip to content

Commit f57abb6

Browse files
committed
fix(pages): inject <base href> for classic-dashboard on GitHub Pages
Direct visits to /repo/classic-dashboard (no trailing slash) resolve ./static relative to /repo and load no JS. Inject base only in deploy workflow before expo export so local dev and desktop export keep relative asset paths. Made-with: Cursor
1 parent 5517614 commit f57abb6

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ jobs:
6262
- name: Install dependencies
6363
run: npm ci
6464

65+
# CRA uses relative ./static/* ; without a trailing slash, /repo/classic-dashboard resolves
66+
# ./static to /repo/static (wrong). <base href> fixes direct links to .../classic-dashboard
67+
- name: Classic dashboard base URL for Pages
68+
env:
69+
CLASSIC_BASE_HREF: /${{ github.event.repository.name }}/classic-dashboard
70+
run: node scripts/inject-classic-dashboard-base.cjs
71+
6572
- name: Export web (static)
6673
env:
6774
EXPO_PUBLIC_BASE_PATH: /${{ github.event.repository.name }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* GitHub Pages only: insert <base href=".../classic-dashboard/"> so direct visits to
3+
* /repo/classic-dashboard (no trailing slash) still resolve ./static/* correctly.
4+
* Local dev and desktop export keep the committed index.html without this tag.
5+
*/
6+
const fs = require('fs');
7+
const path = require('path');
8+
9+
const base = (process.env.CLASSIC_BASE_HREF || '').trim();
10+
if (!base) {
11+
process.exit(0);
12+
}
13+
14+
const indexPath = path.join(__dirname, '..', 'public', 'classic-dashboard', 'index.html');
15+
if (!fs.existsSync(indexPath)) {
16+
console.warn('inject-classic-dashboard-base: skip, missing', indexPath);
17+
process.exit(0);
18+
}
19+
20+
let html = fs.readFileSync(indexPath, 'utf8');
21+
if (/<base\s/i.test(html)) {
22+
process.exit(0);
23+
}
24+
25+
const href = base.endsWith('/') ? base : `${base}/`;
26+
html = html.replace(/<head>/i, `<head><base href="${href}" />`);
27+
fs.writeFileSync(indexPath, html);
28+
console.log('inject-classic-dashboard-base: set base href to', href);

0 commit comments

Comments
 (0)