multi-hosts

This commit is contained in:
Aiden McClelland
2023-05-09 21:29:53 -06:00
parent bb59b96e64
commit e5e392392f
8 changed files with 232 additions and 83 deletions

View File

@@ -1,12 +1,10 @@
export class Origin {
constructor(readonly protocol: string | null, readonly host: string) {}
import { Address } from "../types"
import { Host, PortOptions } from "./Host"
build({ username, path, search }: BuildOptions) {
// prettier-ignore
const urlAuth = !!(username) ? `${username}@` :
'';
const protocolSection = this.protocol != null ? `${this.protocol}://` : ""
export class Origin<T extends Host> {
constructor(readonly host: T, readonly options: PortOptions) {}
build({ username, path, search }: BuildOptions): Address {
const qpEntries = Object.entries(search)
.map(
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
@@ -15,7 +13,12 @@ export class Origin {
const qp = qpEntries.length ? `?${qpEntries}` : ""
return `${protocolSection}${urlAuth}${this.host}${path}${qp}`
return {
hostId: this.host.options.id,
options: this.options,
suffix: `${path}${qp}`,
username,
}
}
}