From 69b45e1cf02f8f8730257c1ff002951eaada3446 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 24 Feb 2022 21:29:33 +0100 Subject: [PATCH] Support custom seed ports via URLs Signed-off-by: Alexis Sellier --- src/base/seeds/Seed.spec.ts | 48 +++++++++++++++++++++++++++++++++++++ src/base/seeds/Seed.ts | 8 +++++-- src/config.json | 2 +- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/base/seeds/Seed.spec.ts diff --git a/src/base/seeds/Seed.spec.ts b/src/base/seeds/Seed.spec.ts new file mode 100644 index 000000000..037ac87b5 --- /dev/null +++ b/src/base/seeds/Seed.spec.ts @@ -0,0 +1,48 @@ +import { Seed } from "./Seed"; +import { Config } from "@app/config"; + +describe('Seed', function () { + it("Constructs git host correctly", () => { + const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null); + const seed = new Seed({ + host: "seed.cloudhead.io", + id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6", + git: "git.seed.cloudhead.io", + }, cfg); + + expect(seed.git.host).to.eq("git.seed.cloudhead.io"); + expect(seed.git.port).to.eq(443); + + expect(seed.host).to.eq("seed.cloudhead.io"); + expect(seed.api.host).to.eq(seed.host); + expect(seed.api.port).to.eq(8777); + }); + + it("Constructs git host correctly with custom port", () => { + const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null); + const seed = new Seed({ + host: "seed.cloudhead.io", + id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6", + git: "https://git.seed.cloudhead.io:8778", + }, cfg); + + expect(seed.git.host).to.eq("git.seed.cloudhead.io"); + expect(seed.git.port).to.eq(8778); + }); + + it("Constructs api host correctly", () => { + const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null); + const seed = new Seed({ + host: "seed.cloudhead.io", + id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6", + api: "https://api.seed.cloudhead.io:8080", + }, cfg); + + expect(seed.api.host).to.eq("api.seed.cloudhead.io"); + expect(seed.api.port).to.eq(8080); + + expect(seed.host).to.eq("api.seed.cloudhead.io"); + expect(seed.git.host).to.eq("seed.cloudhead.io"); + expect(seed.git.port).to.eq(443); + }); +}); diff --git a/src/base/seeds/Seed.ts b/src/base/seeds/Seed.ts index 59c9949ef..c4dfa18d0 100644 --- a/src/base/seeds/Seed.ts +++ b/src/base/seeds/Seed.ts @@ -38,11 +38,14 @@ export class Seed { let api = null; let git = null; + let apiPort = null; + let gitPort = null; if (seed.api) { try { const url = new URL(seed.api); api = url.hostname; + apiPort = url.port || null; } catch { api = seed.api; } @@ -53,6 +56,7 @@ export class Seed { try { const url = new URL(seed.git); git = url.hostname; + gitPort = url.port || null; } catch { git = seed.git; } @@ -71,8 +75,8 @@ export class Seed { api = api ?? seed.host; git = git ?? seed.host; - this.api = { host: api, port: cfg.seed.api.port }; - this.git = { host: git, port: cfg.seed.git.port }; + this.api = { host: api, port: Number(apiPort) || cfg.seed.api.port }; + this.git = { host: git, port: Number(gitPort) || cfg.seed.git.port }; this.link = { host: seed.host, id: seed.id, port: cfg.seed.link.port }; if (seed.version) { diff --git a/src/config.json b/src/config.json index 92261026a..4abcd4c0a 100644 --- a/src/config.json +++ b/src/config.json @@ -90,7 +90,7 @@ "seed": { "api": { "port": 8777 }, "link": { "port": 8776 }, - "git": { "port": 80 } + "git": { "port": 443 } } }, "ipfs": { "gateway": "https://ipfs.io/ipfs/" },