feat: Origins can be null

This commit is contained in:
BluJ
2023-05-02 16:47:37 -06:00
parent 9ec7ec1fa2
commit 29a0bf4981
3 changed files with 5 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ export const ipv6 = once(
export const local = once(() => /\.local/)
export class LocalBinding {
constructor(readonly localHost: string, readonly ipHosts: string[]) {}
createOrigins(protocol: string) {
createOrigins(protocol: string | null) {
const ipHosts = this.ipHosts
return {
local: new Origin(protocol, this.localHost),

View File

@@ -1,5 +1,5 @@
export class Origin {
constructor(readonly protocol: string, readonly host: string) {}
constructor(readonly protocol: string | null, readonly host: string) {}
withAuth(
origin?:
@@ -13,6 +13,7 @@ export class Origin {
// prettier-ignore
const urlAuth = !!(origin) ? `${origin.username}${origin.password != null ?`:${origin.password}`:''}@` :
'';
return `${this.protocol}://${urlAuth}${this.host}`
const protocolSection = this.protocol != null ? `${this.protocol}://` : ""
return `${protocolSection}${urlAuth}${this.host}`
}
}

View File

@@ -2,7 +2,7 @@ import { Origin } from "./Origin"
export class TorBinding {
constructor(readonly host: string) {}
createOrigin(protocol: string) {
createOrigin(protocol: string | null) {
return new Origin(protocol, this.host)
}
}