Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: open link with search params#16617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfrom16501-term
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletionssite/src/utils/portForward.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
import { portForwardURL } from "./portForward";

describe("port forward URL", () => {
const proxyHostWildcard = "*.proxy-host.tld";
const samplePort = 12345;
const sampleAgent = "my-agent";
const sampleWorkspace = "my-workspace";
const sampleUsername = "my-username";

it("https, host and port", () => {
const forwarded = portForwardURL(
proxyHostWildcard,
samplePort,
sampleAgent,
sampleWorkspace,
sampleUsername,
"https",
);
expect(forwarded).toEqual(
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/",
);
});
it("http, host, port and path", () => {
const forwarded = portForwardURL(
proxyHostWildcard,
samplePort,
sampleAgent,
sampleWorkspace,
sampleUsername,
"http",
"/path1/path2",
);
expect(forwarded).toEqual(
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2",
);
});
it("https, host, port, path and empty params", () => {
const forwarded = portForwardURL(
proxyHostWildcard,
samplePort,
sampleAgent,
sampleWorkspace,
sampleUsername,
"https",
"/path1/path2",
"?",
);
expect(forwarded).toEqual(
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?",
);
});
it("http, host, port, path and query params", () => {
const forwarded = portForwardURL(
proxyHostWildcard,
samplePort,
sampleAgent,
sampleWorkspace,
sampleUsername,
"http",
"/path1/path2",
"?key1=value1&key2=value2",
);
expect(forwarded).toEqual(
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?key1=value1&key2=value2",
);
});
});
13 changes: 11 additions & 2 deletionssite/src/utils/portForward.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@ export const portForwardURL = (
workspaceName: string,
username: string,
protocol: WorkspaceAgentPortShareProtocol,
pathname?: string,
search?: string,
): string => {
const { location } = window;
const suffix = protocol === "https" ? "s" : "";
Expand All@@ -15,7 +17,12 @@ export const portForwardURL = (

const baseUrl = `${location.protocol}//${host.replace("*", subdomain)}`;
const url = new URL(baseUrl);

if (pathname) {
url.pathname = pathname;
}
if (search) {
url.search = search;
}
return url.toString();
};

Expand DownExpand Up@@ -63,7 +70,9 @@ export const openMaybePortForwardedURL = (
workspaceName,
username,
url.protocol.replace(":", "") as WorkspaceAgentPortShareProtocol,
) + url.pathname,
url.pathname,
url.search,
),
);
} catch (ex) {
open(uri);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp