feat: Local binding now has all

This commit is contained in:
BluJ
2023-05-02 09:39:31 -06:00
parent 9de6f2d080
commit b58d58ca7c

View File

@@ -14,14 +14,23 @@ export const ipv6 = once(
() =>
/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/,
)
/**
* Some addresses are local
*/
export const local = once(() => /\.local/)
export class LocalBinding {
constructor(readonly localHost: string, readonly ipHosts: string[]) {}
createOrigins(protocol: string) {
const ipHosts = this.ipHosts
return {
local: new Origin(protocol, this.localHost),
get all() {
return [this.local, ...this.ip]
},
get ip() {
return ipHosts.map((x) => new Origin(protocol, x))
return ipHosts
.filter((x) => !local().test(x))
.map((x) => new Origin(protocol, x))
},
get ipv4() {
return ipHosts