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

refactor: improve apps.ts readbility#17741

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
BrunoQuaresma merged 2 commits intomainfrombq/refactor-apps.ts
May 9, 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
8 changes: 8 additions & 0 deletionssite/migrate-icons.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
Look for all the @mui/icons-material icons below and replace them accordinlying with the Lucide icon:

MUI | Lucide
TaskAlt | CircleCheckBigIcon
InfoOutlined | InfoIcon
ErrorOutline | CircleAlertIcon

You should update the imports and usage.
38 changes: 16 additions & 22 deletionssite/src/modules/apps/apps.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,17 +83,11 @@ export const getAppHref = (
: app.url;
}

// The backend redirects if the trailing slash isn't included, so we add it
// here to avoid extra roundtrips.
let href = `${path}/@${workspace.owner_name}/${workspace.name}.${
agent.name
}/apps/${encodeURIComponent(app.slug)}/`;

if (app.command) {
// Terminal links are relative. The terminal page knows how
// to select the correct workspace proxy for the websocket
// connection.
href = `/@${workspace.owner_name}/${workspace.name}.${
return `/@${workspace.owner_name}/${workspace.name}.${
agent.name
}/terminal?command=${encodeURIComponent(app.command)}`;
}
Expand All@@ -102,23 +96,14 @@ export const getAppHref = (
const baseUrl = `${window.location.protocol}//${host.replace(/\*/g, app.subdomain_name)}`;
const url = new URL(baseUrl);
url.pathname = "/";
href = url.toString();
}

return href;
};

export const needsSessionToken = (app: WorkspaceApp) => {
if (!isExternalApp(app)) {
return false;
return url.toString();
}

// HTTP links should never need the session token, since Cookies
// handle sharing it when you access the Coder Dashboard. We should
// never be forwarding the bare session token to other domains!
const isHttp = app.url.startsWith("http");
const requiresSessionToken = app.url.includes(SESSION_TOKEN_PLACEHOLDER);
return requiresSessionToken && !isHttp;
// The backend redirects if the trailing slash isn't included, so we add it
// here to avoid extra roundtrips.
return `${path}/@${workspace.owner_name}/${workspace.name}.${
agent.name
}/apps/${encodeURIComponent(app.slug)}/`;
};

type ExternalWorkspaceApp = WorkspaceApp & {
Expand All@@ -131,3 +116,12 @@ export const isExternalApp = (
): app is ExternalWorkspaceApp => {
return app.external && app.url !== undefined;
};

export const needsSessionToken = (app: ExternalWorkspaceApp) => {
// HTTP links should never need the session token, since Cookies
// handle sharing it when you access the Coder Dashboard. We should
// never be forwarding the bare session token to other domains!
const isHttp = app.url.startsWith("http");
const requiresSessionToken = app.url.includes(SESSION_TOKEN_PLACEHOLDER);
return requiresSessionToken && !isHttp;
};
2 changes: 1 addition & 1 deletionsite/src/modules/apps/useAppLink.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,7 +34,7 @@ export const useAppLink = (
const href = getAppHref(app, {
agent,
workspace,
token: apiKeyResponse?.key ?? "",
token: apiKeyResponse?.key,
path: proxy.preferredPathAppURL,
host: proxy.preferredWildcardHostname,
});
Expand Down
4 changes: 2 additions & 2 deletionssite/src/modules/resources/AppLink/AppLink.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ import {
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { useProxy } from "contexts/ProxyContext";
import { needsSessionToken } from "modules/apps/apps";
import {isExternalApp,needsSessionToken } from "modules/apps/apps";
import { useAppLink } from "modules/apps/useAppLink";
import { type FC, useState } from "react";
import { AgentButton } from "../AgentButton";
Expand DownExpand Up@@ -65,7 +65,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
"Your admin has not configured subdomain application access";
}

if (needsSessionToken(app) && !link.hasToken) {
if (isExternalApp(app) &&needsSessionToken(app) && !link.hasToken) {
canClick = false;
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp