mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-08-04 14:37:34 +00:00
Synthesize DigitalOcean API CORS preflight responses (#477)
This commit is contained in:
parent
0445af0a95
commit
5d083bc22c
1 changed files with 18 additions and 2 deletions
|
|
@ -150,13 +150,29 @@ function getWebAppUrl() {
|
|||
|
||||
// Digital Ocean stopped sending 'Acces-Control-Allow-Origin' headers in some API responses
|
||||
// (i.e. v2/droplets). As a workaround, intercept DO API requests and preemptively inject the
|
||||
// header to allow our origin.
|
||||
// header to allow our origin. Additionally, some OPTIONS requests return 403. Modify the response
|
||||
// status code and inject CORS response headers.
|
||||
function workaroundDigitalOceanApiCors() {
|
||||
const headersFilter = {urls: ['https://api.digitalocean.com/*']};
|
||||
electron.session.defaultSession.webRequest.onHeadersReceived(
|
||||
// tslint:disable-next-line:no-any
|
||||
headersFilter, (details: any, callback: Function) => {
|
||||
details.responseHeaders['access-control-allow-origin'] = ['outline://web_app'];
|
||||
if (details.method === 'OPTIONS') {
|
||||
details.responseHeaders['access-control-allow-origin'] = ['outline://web_app'];
|
||||
if (details.statusCode === 403) {
|
||||
details.statusCode = 200;
|
||||
details.statusLine = 'HTTP/1.1 200';
|
||||
details.responseHeaders['status'] = ['200'];
|
||||
details.responseHeaders['access-control-allow-headers'] =
|
||||
[details.headers['Access-Control-Request-Headers']];
|
||||
details.responseHeaders['access-control-allow-credentials'] = ['true'];
|
||||
details.responseHeaders['access-control-allow-methods'] =
|
||||
['GET, POST, PUT, PATCH, DELETE, OPTIONS'];
|
||||
details.responseHeaders['access-control-expose-headers'] =
|
||||
['RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, Total, Link'];
|
||||
details.responseHeaders['access-control-max-age'] = ['86400'];
|
||||
}
|
||||
}
|
||||
callback(details);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue