Merge pull request #1510 from dan1d/issue-1505

Allow https to follow redirection when requesting latest release data
This commit is contained in:
Sean Yesmunt 2018-05-31 22:06:52 -04:00 committed by GitHub
commit dbe65c2bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,11 +176,11 @@ ipcMain.on('version-info-requested', () => {
},
};
let result = '';
const req = https.get(Object.assign(opts, url.parse(latestReleaseAPIURL)), res => {
const onSuccess = res => {
res.on('data', data => {
result += data;
});
res.on('end', () => {
const tagName = JSON.parse(result).tag_name;
const [, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
@ -199,14 +199,27 @@ ipcMain.on('version-info-requested', () => {
}
}
});
});
};
req.on('error', err => {
console.log('Failed to get current version from GitHub. Error:', err);
if (rendererWindow) {
rendererWindow.webContents.send('version-info-received', null);
}
});
const requestLatestRelease = (apiUrl, alreadyRedirected = false) => {
const req = https.get(Object.assign(opts, url.parse(apiUrl)), res => {
if (res.statusCode === 301 || res.statusCode === 302) {
requestLatestRelease(res.headers.location, true);
} else {
onSuccess(res);
}
});
if (alreadyRedirected) return;
req.on('error', err => {
console.log('Failed to get current version from GitHub. Error:', err);
if (rendererWindow) {
rendererWindow.webContents.send('version-info-received', null);
}
});
};
requestLatestRelease(latestReleaseAPIURL);
});
ipcMain.on('get-auth-token', event => {