patchIndexHTML injects the fetch interceptor and adjusts paths for static hosting.
(html string, basePath string)
| 264 | |
| 265 | // patchIndexHTML injects the fetch interceptor and adjusts paths for static hosting. |
| 266 | func patchIndexHTML(html string, basePath string) string { |
| 267 | // Rewrite absolute asset paths to relative |
| 268 | html = strings.ReplaceAll(html, `="/assets/`, `="./assets/`) |
| 269 | html = strings.ReplaceAll(html, `="/favicon`, `="./favicon`) |
| 270 | |
| 271 | // Ensure trailing slash on basePath |
| 272 | if !strings.HasSuffix(basePath, "/") { |
| 273 | basePath += "/" |
| 274 | } |
| 275 | |
| 276 | // Always inject <base href> so relative paths resolve from root, |
| 277 | // even when served from subdirectory SPA fallbacks like /board/index.html. |
| 278 | baseTag := fmt.Sprintf(`<base href="%s">`, basePath) |
| 279 | html = strings.Replace(html, "<head>", "<head>\n "+baseTag, 1) |
| 280 | |
| 281 | // Inject fetch interceptor and EventSource stub before </head> |
| 282 | html = strings.Replace(html, "</head>", fetchInterceptorScript()+"</head>", 1) |
| 283 | |
| 284 | return html |
| 285 | } |
| 286 | |
| 287 | func fetchInterceptorScript() string { |
| 288 | return `<script> |