fix(electron): add refer/origin to api requests (#9880)

related to BS-2181
This commit is contained in:
pengx17
2025-02-02 10:05:02 +00:00
parent a95803d33b
commit 3834699c68
4 changed files with 19 additions and 9 deletions
@@ -41,10 +41,19 @@ function isNetworkResource(pathname: string) {
}
async function handleFileRequest(request: Request) {
const urlObject = new URL(request.url);
// Redirect to webpack dev server if defined
if (process.env.DEV_SERVER_URL) {
const devServerUrl = new URL(
urlObject.pathname,
process.env.DEV_SERVER_URL
);
return net.fetch(devServerUrl.toString(), request);
}
const clonedRequest = Object.assign(request.clone(), {
bypassCustomProtocolHandlers: true,
});
const urlObject = new URL(request.url);
// this will be file types (in the web-static folder)
let filepath = '';
// if is a file type, load the file in resources
@@ -181,6 +190,12 @@ export function registerProtocol() {
.join('; ');
delete details.requestHeaders['cookie'];
details.requestHeaders['Cookie'] = cookieString;
// mitigate the issue of the worker not being able to access the origin
if (isNetworkResource(pathname)) {
details.requestHeaders['origin'] = url.origin;
details.requestHeaders['referer'] = url.origin;
}
}
})()
.catch(err => {