Support custom seed ports via URLs

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-02-24 21:31:54 +01:00
parent 19c1676f50
commit 69b45e1cf0
3 changed files with 55 additions and 3 deletions
+48
View File
@@ -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);
});
});
+6 -2
View File
@@ -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) {
+1 -1
View File
@@ -90,7 +90,7 @@
"seed": {
"api": { "port": 8777 },
"link": { "port": 8776 },
"git": { "port": 80 }
"git": { "port": 443 }
}
},
"ipfs": { "gateway": "https://ipfs.io/ipfs/" },