Merge pull request #647 from Jigsaw-Code/fortuna-do

Fix DO API
This commit is contained in:
Vinicius Fortuna 2020-05-13 11:12:30 -04:00 committed by GitHub
commit a789c29a16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -100,7 +100,7 @@ class RestApiSession implements DigitalOceanSession {
public getAccount(): Promise<Account> {
console.info('Requesting account');
return this.request<{account: Account}>('GET', 'account/').then((response) => {
return this.request<{account: Account}>('GET', 'account').then((response) => {
return response.account;
});
}
@ -179,7 +179,7 @@ class RestApiSession implements DigitalOceanSession {
public getDroplet(dropletId: number): Promise<DropletInfo> {
console.info('Requesting droplet');
return this.request<{droplet: DropletInfo}>('GET', 'droplets/' + dropletId).then((response) => {
return this.request<{droplet: DropletInfo}>('GET', 'droplets' + dropletId).then((response) => {
return response.droplet;
});
}
@ -192,7 +192,7 @@ class RestApiSession implements DigitalOceanSession {
public getDropletsByTag(tag: string): Promise<DropletInfo[]> {
console.info('Requesting droplet by tag');
return this.request<{droplets: DropletInfo[]}>('GET', `droplets/?tag_name=${encodeURI(tag)}`)
return this.request<{droplets: DropletInfo[]}>('GET', `droplets?tag_name=${encodeURI(tag)}`)
.then((response) => {
return response.droplets;
});
@ -200,7 +200,7 @@ class RestApiSession implements DigitalOceanSession {
public getDroplets(): Promise<DropletInfo[]> {
console.info('Requesting droplets');
return this.request<{droplets: DropletInfo[]}>('GET', 'droplets/').then((response) => {
return this.request<{droplets: DropletInfo[]}>('GET', 'droplets').then((response) => {
return response.droplets;
});
}

View file

@ -147,26 +147,24 @@ function getWebAppUrl() {
// 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) => {
electron.session.defaultSession.webRequest.onHeadersReceived(headersFilter,
(details: electron.OnHeadersReceivedListenerDetails, callback: (response: electron.CallbackResponse) => void) => {
if (details.method === 'OPTIONS') {
details.responseHeaders['access-control-allow-origin'] = ['outline://web_app'];
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['status'] = '200';
details.responseHeaders['access-control-allow-headers'] = '*';
details.responseHeaders['access-control-allow-credentials'] = 'true';
details.responseHeaders['access-control-allow-methods'] =
['GET, POST, PUT, PATCH, DELETE, OPTIONS'];
'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'];
'RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, Total, Link';
details.responseHeaders['access-control-max-age'] = '86400';
}
}
callback(details);
callback(details as electron.CallbackResponse);
});
}