Skip to content

fix: use url-parse for url construction #15670

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 27, 2024
Next Next commit
fix: fix incomplete string escaping
  • Loading branch information
sreya committed Nov 26, 2024
commit a612a54bf36f9436f316e8c9610cbea5be7e7368
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"storybook": "pnpm run -C site/ storybook"
},
"devDependencies": {
"@types/url-parse": "^1.4.11",
"prettier": "3.3.3"
},
"dependencies": {
"url-parse": "^1.5.10"
}
}
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions site/src/utils/apps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as TypesGen from "api/typesGenerated";
import URLParse from 'url-parse';

export const createAppLinkHref = (
protocol: string,
Expand All @@ -16,20 +17,25 @@ export const createAppLinkHref = (

// The backend redirects if the trailing slash isn't included, so we add it
// here to avoid extra roundtrips.
let href = `${preferredPathBase}/@${username}/${workspace.name}.${
let path = `${preferredPathBase}/@${username}/${workspace.name}.${
agent.name
}/apps/${encodeURIComponent(appSlug)}/`;
if (app.command) {
// Terminal links are relative. The terminal page knows how
// to select the correct workspace proxy for the websocket
// connection.
href = `/@${username}/${workspace.name}.${
path = `/@${username}/${workspace.name}.${
agent.name
}/terminal?command=${encodeURIComponent(app.command)}`;
}

if (appsHost && app.subdomain && app.subdomain_name) {
href = `${protocol}//${appsHost}/`.replace("*", app.subdomain_name);
const url = new URLParse('');
url.set('protocol', protocol);
url.set('hostname', appsHost.replace('*', app.subdomain_name));
url.set('pathname', '/');

path = url.toString();
}
return href;
return path;
};