Skip to content

Commit b185fb6

Browse files
committed
fix(console): 支持 BAILIAN_PRE 环境变量切换预发布地址
- login-console 模块新增 BAILIAN_PRE 判断,切换控制台源地址为 pre- 子域名 - core.console.gateway 模块新增 isPreEnv 和 applyPrePrefix 函数封装预发布环境判断和前缀处理 - 调整控制台网关地址拼接逻辑,支持在预发布环境自动添加 pre- 前缀 - 保持默认行为不变,仅在预发布环境下生效预发布子域名切换
1 parent 503e146 commit b185fb6

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/cli/src/commands/auth/login-console.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ const CONSOLE_ORIGINS: Record<string, string> = {
2222
};
2323

2424
export function resolveConsoleOrigin(site?: string): string {
25-
return (site && CONSOLE_ORIGINS[site]) || CONSOLE_ORIGINS.domestic!;
25+
const origin = (site && CONSOLE_ORIGINS[site]) || CONSOLE_ORIGINS.domestic!;
26+
if (process.env.BAILIAN_PRE) {
27+
const u = new URL(origin);
28+
u.hostname = `pre-${u.hostname}`;
29+
return u.origin;
30+
}
31+
return origin;
2632
}
2733

2834
function readBodyBounded(req: http.IncomingMessage): Promise<string> {

packages/core/src/console/gateway.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ function resolveGateway(region: string, site: ConsoleSite): ConsoleGatewayInfo {
3535
return REGION_GATEWAYS[region]?.[site] ?? REGION_GATEWAYS["cn-beijing"]![site];
3636
}
3737

38+
export function isPreEnv(): boolean {
39+
return !!process.env.BAILIAN_PRE;
40+
}
41+
42+
function applyPrePrefix(host: string): string {
43+
return isPreEnv() ? `pre-${host}` : host;
44+
}
45+
3846
/** Resolved console gateway settings (same defaults as {@link callConsoleGateway}). */
3947
export function effectiveConsoleGatewayConfig(config: Config): {
4048
consoleRegion: string;
@@ -106,7 +114,7 @@ export async function callConsoleGateway(
106114
} = effectiveConsoleGatewayConfig(config);
107115

108116
const resolved = resolveGateway(effectiveRegion, effectiveSite);
109-
const gatewayBase = `https://${resolved.csGateway}`;
117+
const gatewayBase = `https://${applyPrePrefix(resolved.csGateway)}`;
110118
const action = resolved.action;
111119

112120
const params = buildGatewayParams(api, data, effectiveSwitchAgent);

0 commit comments

Comments
 (0)