diff --git a/packages/electron-builder-publisher/src/gitHubPublisher.ts b/packages/electron-builder-publisher/src/gitHubPublisher.ts index 664300482db..6c292c12e47 100644 --- a/packages/electron-builder-publisher/src/gitHubPublisher.ts +++ b/packages/electron-builder-publisher/src/gitHubPublisher.ts @@ -187,8 +187,11 @@ export class GitHubPublisher extends HttpPublisher { } private githubRequest(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise { + // host can contains port, but node http doesn't support host as url does + const baseUrl = parseUrl(`https://${this.info.host || "api.github.com"}`) return httpExecutor.request(configureRequestOptions({ - host: this.info.host || "api.github.com", + hostname: baseUrl.hostname, + port: baseUrl.port, path: (this.info.host != null && this.info.host !== "github.com") ? `/api/v3/${path}` : path, headers: {Accept: "application/vnd.github.v3+json"} }, token, method), this.context.cancellationToken, data) diff --git a/packages/electron-updater/src/GitHubProvider.ts b/packages/electron-updater/src/GitHubProvider.ts index 5d853f4af1e..91844a8f2ed 100644 --- a/packages/electron-updater/src/GitHubProvider.ts +++ b/packages/electron-updater/src/GitHubProvider.ts @@ -4,10 +4,22 @@ import { validateUpdateInfo } from "./GenericProvider" import * as path from "path" import { HttpError, request } from "electron-builder-http" import { CancellationToken } from "electron-builder-http/out/CancellationToken" +import * as url from "url" +import { RequestOptions } from "http" export class GitHubProvider extends Provider { + // so, we don't need to parse port (because node http doesn't support host as url does) + private readonly baseUrl: RequestOptions + constructor(private readonly options: GithubOptions) { super() + + const baseUrl = url.parse(`${options.protocol || "https:"}//${options.host || "github.com"}`) + this.baseUrl = { + protocol: baseUrl.protocol, + hostname: baseUrl.hostname, + port: baseUrl.port, + } } async getLatestVersion(): Promise { @@ -15,16 +27,12 @@ export class GitHubProvider extends Provider { let version const cancellationToken = new CancellationToken() - const host = this.options.host || "github.com" - const protocol = `${this.options.protocol || "https"}:` try { // do not use API to avoid limit - const releaseInfo = (await request({ - protocol: protocol, - host: host, + const releaseInfo = (await request(Object.assign({ path: `${basePath}/latest`, headers: Object.assign({Accept: "application/json"}, this.requestHeaders) - }, cancellationToken)) + }, this.baseUrl), cancellationToken)) version = (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name } catch (e) { @@ -35,7 +43,7 @@ export class GitHubProvider extends Provider { const channelFile = getChannelFilename(getDefaultChannelName()) const channelFileUrlPath = `${basePath}/download/v${version}/${channelFile}` try { - result = await request({protocol: protocol, host: host, path: channelFileUrlPath, headers: this.requestHeaders || undefined}, cancellationToken) + result = await request(Object.assign({path: channelFileUrlPath, headers: this.requestHeaders || undefined}, this.baseUrl), cancellationToken) } catch (e) { if (e instanceof HttpError && e.response.statusCode === 404) { @@ -65,7 +73,7 @@ export class GitHubProvider extends Provider { const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-") return { name: name, - url: `https://github.com${basePath}/download/v${versionInfo.version}/${name}`, + url: url.format(Object.assign({pathname: `${basePath}/download/v${versionInfo.version}/${name}`}, this.baseUrl)), sha2: versionInfo.sha2, } }