From 8ca6e21969e5c081a553371b4ab2683f82932968 Mon Sep 17 00:00:00 2001 From: Daniel Dominguez Date: Wed, 23 May 2018 16:30:45 -0300 Subject: [PATCH] Allow https to follow redirections when requesting latest release data from github. --- src/main/index.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 2591e20f6..276212b59 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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 => { -- 2.45.2