Skip to content

Commit 31c2058

Browse files
Fixed host issue in NO_PROXY
1 parent 0437b6e commit 31c2058

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

packages/contentstack-utilities/src/proxy-helper.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,34 @@ export function getProxyConfigForHost(host: string): ProxyConfig | undefined {
147147
return getProxyConfig();
148148
}
149149

150-
export function resolveRequestHost(config: { host?: string }): string {
151-
if (config.host) return config.host;
150+
function regionCmaHostname(): string {
152151
const cma = configStore.get('region')?.cma;
153-
if (cma && typeof cma === 'string') {
154-
if (cma.startsWith('http')) {
155-
try {
156-
const u = new URL(cma);
157-
return u.hostname || cma;
158-
} catch {
159-
return cma;
160-
}
152+
if (!cma || typeof cma !== 'string') {
153+
return '';
154+
}
155+
if (cma.startsWith('http')) {
156+
try {
157+
const u = new URL(cma);
158+
return u.hostname || cma;
159+
} catch {
160+
return cma;
161161
}
162-
return cma;
163162
}
164-
return '';
163+
return cma;
164+
}
165+
166+
167+
export function resolveRequestHost(config: { host?: string }): string {
168+
const fromRegion = regionCmaHostname();
169+
if (fromRegion) {
170+
return normalizeHost(fromRegion) || fromRegion;
171+
}
172+
173+
const raw = config.host?.trim() || '';
174+
if (!raw) {
175+
return '';
176+
}
177+
return normalizeHost(raw) || raw;
165178
}
166179

167180
export function clearProxyEnv(): () => void {

0 commit comments

Comments
 (0)