mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Enable localhost connections in radicle-explorer
Allow radicle-explorer to connect to a locally running radicle-httpd via https://app.radicle.xyz/nodes/localhost. This was previously disabled to encourage use of Radicle Desktop, but is now useful for testing the new always-on node in local development environments. Remove support for /nodes/radicle.local, an undocumented and unused convention. Fix remote node loading when Cloudflare URL-encodes port separator (: → %3A).
This commit is contained in:
+23
-29
@@ -145,37 +145,31 @@ export async function replace(newRoute: Route): Promise<void> {
|
||||
await navigate("replace", newRoute);
|
||||
}
|
||||
|
||||
function extractBaseUrl(hostAndPort: string): BaseUrl {
|
||||
if (
|
||||
hostAndPort === "radicle.local" ||
|
||||
hostAndPort === `radicle.local:${config.nodes.defaultHttpdPort}` ||
|
||||
hostAndPort === "0.0.0.0" ||
|
||||
hostAndPort === `0.0.0.0:${config.nodes.defaultHttpdPort}` ||
|
||||
hostAndPort === "127.0.0.1" ||
|
||||
hostAndPort === `127.0.0.1:${config.nodes.defaultHttpdPort}`
|
||||
) {
|
||||
return {
|
||||
hostname: "127.0.0.1",
|
||||
port: config.nodes.defaultHttpdPort,
|
||||
scheme: "http",
|
||||
};
|
||||
} else if (hostAndPort.includes(":")) {
|
||||
const [hostname, port] = hostAndPort.split(":");
|
||||
return {
|
||||
hostname,
|
||||
port: Number(port),
|
||||
scheme:
|
||||
utils.isLocal(hostname) || utils.isOnion(hostname)
|
||||
? "http"
|
||||
: config.nodes.defaultHttpdScheme,
|
||||
};
|
||||
export function extractBaseUrl(hostAndPort: string): BaseUrl {
|
||||
const [hostname, portString] = decodeURIComponent(hostAndPort).split(":");
|
||||
|
||||
let port;
|
||||
|
||||
if (portString !== undefined) {
|
||||
port = Number(portString);
|
||||
} else if (globalThis.__PLAYWRIGHT__ === true) {
|
||||
port = config.nodes.defaultHttpdPort;
|
||||
} else {
|
||||
return {
|
||||
hostname: hostAndPort,
|
||||
port: config.nodes.defaultHttpdPort,
|
||||
scheme: config.nodes.defaultHttpdScheme,
|
||||
};
|
||||
port = utils.isLocal(hostname)
|
||||
? config.nodes.defaultLocalHttpdPort
|
||||
: config.nodes.defaultHttpdPort;
|
||||
}
|
||||
|
||||
const scheme =
|
||||
utils.isLocal(hostname) || utils.isOnion(hostname)
|
||||
? "http"
|
||||
: config.nodes.defaultHttpdScheme;
|
||||
|
||||
return {
|
||||
hostname,
|
||||
port,
|
||||
scheme,
|
||||
};
|
||||
}
|
||||
|
||||
function urlToRoute(url: URL): Route | null {
|
||||
|
||||
+1
-5
@@ -205,11 +205,7 @@ export function isMarkdownPath(path: string): boolean {
|
||||
|
||||
// Check whether the given address is a localhost address.
|
||||
export function isLocal(addr: string): boolean {
|
||||
return (
|
||||
addr.startsWith("127.0.0.1") ||
|
||||
addr.startsWith("0.0.0.0") ||
|
||||
addr.startsWith("radicle.local")
|
||||
);
|
||||
return addr.startsWith("127.0.0.1") || addr.startsWith("localhost");
|
||||
}
|
||||
|
||||
// Check whether the given domain name is an onion domain name.
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
selectedSeed,
|
||||
} from "./SeedSelector";
|
||||
import { closeFocused } from "@app/components/Popover.svelte";
|
||||
import { push } from "@app/lib/router";
|
||||
import { extractBaseUrl, push } from "@app/lib/router";
|
||||
|
||||
import DropdownList from "@app/components/DropdownList.svelte";
|
||||
import DropdownListItem from "@app/components/DropdownList/DropdownListItem.svelte";
|
||||
@@ -45,11 +45,7 @@
|
||||
|
||||
async function navigateToSeed() {
|
||||
loading = true;
|
||||
const seed = {
|
||||
hostname: seedAddressInput.trim(),
|
||||
port: config.nodes.defaultHttpdPort,
|
||||
scheme: config.nodes.defaultHttpdScheme,
|
||||
};
|
||||
const seed = extractBaseUrl(seedAddressInput.trim());
|
||||
validationMessage = await validateInput(seed);
|
||||
if (validationMessage === undefined) {
|
||||
closeFocused();
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
|
||||
import config from "@app/lib/config";
|
||||
import { HttpdClient } from "@http-client";
|
||||
import { ResponseError, ResponseParseError } from "@http-client/lib/fetcher";
|
||||
import { baseUrlToString, isLocal } from "@app/lib/utils";
|
||||
import { baseUrlToString } from "@app/lib/utils";
|
||||
import { handleError } from "@app/views/nodes/error";
|
||||
import { unreachableError } from "@app/views/repos/error";
|
||||
import { determineSeed } from "./SeedSelector";
|
||||
@@ -53,17 +53,6 @@ export async function loadNodeRoute(
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
if (import.meta.env.PROD && isLocal(`${baseUrl.hostname}:${baseUrl.port}`)) {
|
||||
return {
|
||||
resource: "error",
|
||||
params: {
|
||||
icon: "device",
|
||||
title: "Local node browsing not supported",
|
||||
description: `You're trying to access a local node from your browser, we are currently working on a desktop app specific for this use case. Join our <strong>#desktop</strong> channel on <radicle-external-link href="${config.supportWebsite}">${config.supportWebsite}</radicle-external-link> for more information.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const [node, stats] = await Promise.all([api.getNode(), api.getStats()]);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import { HttpdClient } from "@http-client";
|
||||
import { ResponseError, ResponseParseError } from "@http-client/lib/fetcher";
|
||||
import { cached } from "@app/lib/cache";
|
||||
import { handleError, unreachableError } from "@app/views/repos/error";
|
||||
import { isLocal, unreachable } from "@app/lib/utils";
|
||||
import { unreachable } from "@app/lib/utils";
|
||||
import { nodePath } from "@app/views/nodes/router";
|
||||
|
||||
export const PATCHES_PER_PAGE = 10;
|
||||
@@ -262,19 +262,6 @@ export async function loadRepoRoute(
|
||||
route: RepoRoute,
|
||||
previousLoaded: LoadedRoute,
|
||||
): Promise<RepoLoadedRoute | ErrorRoute | NotFoundRoute> {
|
||||
if (
|
||||
import.meta.env.PROD &&
|
||||
isLocal(`${route.node.hostname}:${route.node.port}`)
|
||||
) {
|
||||
return {
|
||||
resource: "error",
|
||||
params: {
|
||||
icon: "device",
|
||||
title: "Local node browsing not supported",
|
||||
description: `You're trying to access a repository on a local node from your browser, we are currently working on a desktop app specific for this use case. Join our <strong>#desktop</strong> channel on <radicle-external-link href="${config.supportWebsite}">${config.supportWebsite}</radicle-external-link> for more information.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
const api = new HttpdClient(route.node);
|
||||
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { BaseUrl, NodeIdentity, NodeStats } from "@http-client";
|
||||
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
|
||||
|
||||
import * as utils from "@app/lib/utils";
|
||||
import config from "@app/lib/config";
|
||||
import { HttpdClient } from "@http-client";
|
||||
import { ResponseError, ResponseParseError } from "@http-client/lib/fetcher";
|
||||
import { handleError } from "@app/views/nodes/error";
|
||||
@@ -30,19 +29,6 @@ export async function loadUserRoute({
|
||||
did,
|
||||
baseUrl,
|
||||
}: UserRoute): Promise<UserLoadedRoute | NotFoundRoute | ErrorRoute> {
|
||||
if (
|
||||
import.meta.env.PROD &&
|
||||
utils.isLocal(`${baseUrl.hostname}:${baseUrl.port}`)
|
||||
) {
|
||||
return {
|
||||
resource: "error",
|
||||
params: {
|
||||
icon: "device",
|
||||
title: "Local node browsing not supported",
|
||||
description: `You're trying to access a local node from your browser, we are currently working on a desktop app specific for this use case. Join our <strong>#desktop</strong> channel on <radicle-external-link href="${config.supportWebsite}">${config.supportWebsite}</radicle-external-link> for more information.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
const parsedDid = utils.parseNodeId(decodeURIComponent(did));
|
||||
if (!parsedDid) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user