Skip to content
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

fix(portal-server): 修复获取 scowdClient 时拼接地址的错误 #1362

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changeset/khaki-cheetahs-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/portal-server": patch
"@scow/utils": patch
---

修复获取 scowdClient 时拼接地址的错误
4 changes: 3 additions & 1 deletion apps/portal-server/src/utils/scowd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceError, status } from "@grpc/grpc-js";
import { getLoginNode } from "@scow/config/build/cluster";
import { getScowdClient as getClient, ScowdClient } from "@scow/lib-scowd/build/client";
import { createScowdCertificates } from "@scow/lib-scowd/build/ssl";
import { removePort } from "@scow/utils";
import { configClusters } from "src/config/clusters";
import { config } from "src/config/env";

Expand All @@ -28,7 +29,8 @@ export function getLoginNodeScowdUrl(cluster: string, host: string): string | un
if (!loginNode) return undefined;

const { address, scowdPort } = loginNode;
return config.SCOWD_SSL_ENABLED ? `https://${address}:${scowdPort}` : `http://${address}:${scowdPort}`;
return config.SCOWD_SSL_ENABLED
? `https://${removePort(address)}:${scowdPort}` : `http://${removePort(address)}:${scowdPort}`;
}

const scowdClientForClusters = Object.entries(configClusters).reduce((prev, [cluster]) => {
Expand Down
11 changes: 11 additions & 0 deletions libs/utils/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ export function normalizePathnameWithQuery(pathnameWithQuery: string) {

return normalize(pathname) + qs;
}

/**
* Remove port from address
* @param address IP address or hostname possibly with port
* @returns address without port
*/
export function removePort(address: string): string {
// Remove :port if present
return address.replace(/:\d+$/, "");
}

Loading