Skip to content

Commit e2be4c0

Browse files
rewrite fetch
1 parent b15f1f5 commit e2be4c0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/builder.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,43 @@ const Builder = () => {
4545
<Script id="monaco-editor">
4646
{`
4747
var require = { paths: { 'vs': 'third-party/monaco-editor/package/min/vs' } };
48+
49+
const originalFetch = window.fetch;
50+
window.fetch = function(input, init) {
51+
let url;
52+
if (typeof input === 'string') {
53+
url = input;
54+
} else if (input instanceof Request) {
55+
url = input.url;
56+
} else {
57+
return originalFetch(input, init);
58+
}
59+
60+
try {
61+
const parsedUrl = new URL(url);
62+
const path = parsedUrl.pathname;
63+
64+
if (path.startsWith('/vs')) {
65+
const newPath = \`/third-party/monaco-editor/${monaco_version}/package/min\${path}\`;
66+
67+
return originalFetch(newPath, init);
68+
}
69+
} catch (e) {
70+
if (url.startsWith('vs')) {
71+
const newPath = \`/third-party/monaco-editor/${monaco_version}/package/min/\${url}\`;
72+
73+
return originalFetch(newPath, init);
74+
} else if (url.startsWith('/vs')) {
75+
const newPath = \`/third-party/monaco-editor/${monaco_version}/package/min\${url}\`;
76+
77+
return originalFetch(newPath, init);
78+
} else {
79+
return originalFetch(input, init);
80+
}
81+
}
82+
83+
return originalFetch(input, init);
84+
};
4885
`}
4986
</Script>
5087
<script src={`/third-party/monaco-editor/${monaco_version}/package/min/vs/loader.js`}></script>

0 commit comments

Comments
 (0)