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

Commit5706a11

Browse files
mtojekaslilac
authored andcommitted
fix: open link with search params (#16617)
Fixes:#16501
1 parent5801da2 commit5706a11

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

‎site/src/utils/portForward.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{portForwardURL}from"./portForward";
2+
3+
describe("port forward URL",()=>{
4+
constproxyHostWildcard="*.proxy-host.tld";
5+
constsamplePort=12345;
6+
constsampleAgent="my-agent";
7+
constsampleWorkspace="my-workspace";
8+
constsampleUsername="my-username";
9+
10+
it("https, host and port",()=>{
11+
constforwarded=portForwardURL(
12+
proxyHostWildcard,
13+
samplePort,
14+
sampleAgent,
15+
sampleWorkspace,
16+
sampleUsername,
17+
"https",
18+
);
19+
expect(forwarded).toEqual(
20+
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/",
21+
);
22+
});
23+
it("http, host, port and path",()=>{
24+
constforwarded=portForwardURL(
25+
proxyHostWildcard,
26+
samplePort,
27+
sampleAgent,
28+
sampleWorkspace,
29+
sampleUsername,
30+
"http",
31+
"/path1/path2",
32+
);
33+
expect(forwarded).toEqual(
34+
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2",
35+
);
36+
});
37+
it("https, host, port, path and empty params",()=>{
38+
constforwarded=portForwardURL(
39+
proxyHostWildcard,
40+
samplePort,
41+
sampleAgent,
42+
sampleWorkspace,
43+
sampleUsername,
44+
"https",
45+
"/path1/path2",
46+
"?",
47+
);
48+
expect(forwarded).toEqual(
49+
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?",
50+
);
51+
});
52+
it("http, host, port, path and query params",()=>{
53+
constforwarded=portForwardURL(
54+
proxyHostWildcard,
55+
samplePort,
56+
sampleAgent,
57+
sampleWorkspace,
58+
sampleUsername,
59+
"http",
60+
"/path1/path2",
61+
"?key1=value1&key2=value2",
62+
);
63+
expect(forwarded).toEqual(
64+
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?key1=value1&key2=value2",
65+
);
66+
});
67+
});

‎site/src/utils/portForward.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const portForwardURL = (
77
workspaceName:string,
88
username:string,
99
protocol:WorkspaceAgentPortShareProtocol,
10+
pathname?:string,
11+
search?:string,
1012
):string=>{
1113
const{ location}=window;
1214
constsuffix=protocol==="https" ?"s" :"";
@@ -15,7 +17,12 @@ export const portForwardURL = (
1517

1618
constbaseUrl=`${location.protocol}//${host.replace("*",subdomain)}`;
1719
consturl=newURL(baseUrl);
18-
20+
if(pathname){
21+
url.pathname=pathname;
22+
}
23+
if(search){
24+
url.search=search;
25+
}
1926
returnurl.toString();
2027
};
2128

@@ -63,7 +70,9 @@ export const openMaybePortForwardedURL = (
6370
workspaceName,
6471
username,
6572
url.protocol.replace(":","")asWorkspaceAgentPortShareProtocol,
66-
)+url.pathname,
73+
url.pathname,
74+
url.search,
75+
),
6776
);
6877
}catch(ex){
6978
open(uri);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp