MCPcopy Create free account
hub / github.com/error311/FileRise / patchFetchForBasePath

Function patchFetchForBasePath

public/js/basePath.js:53–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51}
52
53export function patchFetchForBasePath() {
54 if (window.__FR_FETCH_BASEPATCH__) return;
55 window.__FR_FETCH_BASEPATCH__ = true;
56
57 const nativeFetch = window.fetch.bind(window);
58 window.fetch = (input, init) => {
59 try {
60 const base = getBasePath();
61 if (base) {
62 if (typeof input === 'string') {
63 if (input.startsWith('/api/') && !input.startsWith(base + '/api/')) {
64 return nativeFetch(base + input, init);
65 }
66 } else if (input && typeof input.url === 'string') {
67 const u = new URL(input.url, window.location.origin);
68 if (u.origin === window.location.origin && u.pathname.startsWith('/api/') && !u.pathname.startsWith(base + '/api/')) {
69 const rewritten = new URL(base + u.pathname + u.search + u.hash, window.location.origin);
70 const req = new Request(rewritten.toString(), input);
71 return nativeFetch(req, init);
72 }
73 }
74 }
75 } catch (e) {
76 // fall through
77 }
78 return nativeFetch(input, init);
79 };
80}
81

Callers 3

main.jsFile · 0.85
portal-login.jsFile · 0.85
portal.jsFile · 0.85

Calls 1

getBasePathFunction · 0.85

Tested by

no test coverage detected