mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-03 18:50:30 +08:00
Improve localhost detection
This commit is contained in:
+13
-2
@@ -204,8 +204,19 @@ export function isMarkdownPath(path: string): boolean {
|
||||
}
|
||||
|
||||
export function isLocal(addr: string): boolean {
|
||||
// Support *.localhost subdomains and 127.0.0.1.
|
||||
return addr.endsWith("localhost") || addr.startsWith("127.0.0.1");
|
||||
try {
|
||||
const url = new URL(`scheme://${addr}`);
|
||||
const hostname = url.hostname;
|
||||
|
||||
return (
|
||||
hostname === "[::1]" ||
|
||||
hostname === "127.0.0.1" ||
|
||||
hostname === "localhost" ||
|
||||
hostname.endsWith(".localhost")
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the given domain name is an onion domain name.
|
||||
|
||||
Reference in New Issue
Block a user