Skip to content

Commit

Permalink
fix: CORS when using localhost env (#3549)
Browse files Browse the repository at this point in the history
An error in the typings happened a few weeks ago and the docs has been fixed accordingly electron/electron#21730
  • Loading branch information
Sabri committed Feb 5, 2020
1 parent 1111b53 commit 357484e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions electron/src/main.ts
Expand Up @@ -563,22 +563,22 @@ class ElectronWrapperInit {
urls: config.backendOrigins.map(value => `${value}/*`),
};

const listener = (
_details: OnHeadersReceivedListenerDetails,
const listenerOnHeadersReceived = (
details: OnHeadersReceivedListenerDetails,
callback: (response: HeadersReceivedResponse) => void,
) => {
const responseHeaders = {
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Origin': 'http://localhost:8081',
'Access-Control-Allow-Credentials': ['true'],
'Access-Control-Allow-Origin': ['http://localhost:8081'],
};

callback({
cancel: false,
responseHeaders,
responseHeaders: {...details.responseHeaders, ...responseHeaders},
});
};

contents.session.webRequest.onHeadersReceived(filter, listener);
contents.session.webRequest.onHeadersReceived(filter, listenerOnHeadersReceived);
}

contents.on('before-input-event', (_event, input) => {
Expand Down

0 comments on commit 357484e

Please sign in to comment.