Allow URLs to be used for git/api records

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-02-22 21:44:52 +01:00
parent 73f2a988c9
commit 8ca59d11a8
+24 -4
View File
@@ -35,13 +35,33 @@ export class Seed {
assert(isDomain(seed.host), `invalid seed host: ${seed.host}`);
assert(/^[a-z0-9]+$/.test(seed.id), `invalid seed id ${seed.id}`);
seed.api && assert(isDomain(seed.api), `invalid seed api host ${seed.api}`);
seed.git && assert(isDomain(seed.git), `invalid seed git host ${seed.git}`);
let api = null;
let git = null;
if (seed.api) {
try {
const url = new URL(seed.api);
api = url.hostname;
} catch {
api = seed.api;
}
assert(isDomain(api), `invalid seed api host ${api}`);
}
if (seed.git) {
try {
const url = new URL(seed.git);
git = url.hostname;
} catch {
git = seed.git;
}
assert(isDomain(git), `invalid seed git host ${git}`);
}
// The `git` and `api` keys being more specific take
// precedence over the `host`, if available.
const api = seed.api ?? seed.host;
const git = seed.git ?? seed.host;
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 };