()
| 285 | } |
| 286 | |
| 287 | func fetchInterceptorScript() string { |
| 288 | return `<script> |
| 289 | (function() { |
| 290 | var origFetch = window.fetch; |
| 291 | function json(body) { return new Response(body, {status:200, headers:{'Content-Type':'application/json'}}); } |
| 292 | function redir(p, init) { return origFetch('./api/' + p + '.json', init); } |
| 293 | window.fetch = function(input, init) { |
| 294 | var url = (typeof input === 'string') ? input : input.url; |
| 295 | if (url.indexOf('/api/') !== 0 && url.indexOf('./api/') !== 0) return origFetch.apply(this, arguments); |
| 296 | var full = url.replace(/^\.\//, '/'); |
| 297 | var qi = full.indexOf('?'); var p = qi >= 0 ? full.substring(0, qi) : full; var q = qi >= 0 ? full.substring(qi) : ''; |
| 298 | if (p.indexOf('/api/search') === 0) return Promise.resolve(json('[]')); |
| 299 | if (p === '/api/events') return new Promise(function() {}); |
| 300 | if (p === '/api/board') { var bm = q.match(/groupBy=(\w+)/); return redir('board/' + (bm ? bm[1] : 'status'), init); } |
| 301 | var wm = p.match(/^\/api\/tasks\/([^/?]+)\/worklog/); |
| 302 | if (wm) return redir('tasks/' + wm[1] + '/worklog', init); |
| 303 | var tm = p.match(/^\/api\/tasks\/([^/?]+)$/); |
| 304 | if (tm) return redir('tasks/' + tm[1], init); |
| 305 | if (p === '/api/graph/mermaid') return Promise.resolve(new Response('', {status:200, headers:{'Content-Type':'text/plain'}})); |
| 306 | return redir(p.replace(/^\/api\//, ''), init); |
| 307 | }; |
| 308 | window.EventSource = function() { this.close = this.addEventListener = this.removeEventListener = function() {}; }; |
| 309 | })(); |
| 310 | </script> |
| 311 | ` |
| 312 | } |
| 313 | |
| 314 | func generateSPAFallbacks(outputDir, patchedHTML string, tasks []*model.Task) error { |
| 315 | // Top-level SPA routes |
no outgoing calls