Skip to content

Commit

Permalink
fix(portal-server): 修复获取 scowdClient 时拼接地址的错误 (#1362)
Browse files Browse the repository at this point in the history
scow 在获取 scowdClient 时是通过 login 的地址拼接对应 scowd 的 port 的方式获得的 scowd
的完整地址。之前未考虑到 login地址中可能会带上端口,拼接的时候就会出错。所以本次修复主要是移除 login 地址中的端口号再进行拼接
  • Loading branch information
Miracle575 authored Jul 17, 2024
1 parent 6eebd35 commit a9e9011
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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+$/, "");
}

0 comments on commit a9e9011

Please sign in to comment.