From 85b6c18f8871465fbb34b005291e8a80b18d02d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=98=86=E9=B9=8F?= Date: Thu, 21 Jan 2021 21:21:33 +0800 Subject: [PATCH 1/2] fix: fix the request address is undefined after SSL is enabled --- packages/nacos-config/src/http_agent.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/nacos-config/src/http_agent.ts b/packages/nacos-config/src/http_agent.ts index a250dbb..df6a9f8 100644 --- a/packages/nacos-config/src/http_agent.ts +++ b/packages/nacos-config/src/http_agent.ts @@ -23,7 +23,6 @@ import { encodingParams, transformGBKToUTF8 } from './utils'; export class HttpAgent { options; - currentServer: string; protected loggerDomain = 'Nacos'; private debugPrefix = this.loggerDomain.toLowerCase(); private debug = require('debug')(`${this.debugPrefix}:${process.pid}:http_agent`); @@ -188,12 +187,12 @@ export class HttpAgent { if (/:/.test(currentServer)) { url = `http://${currentServer}`; if (this.ssl) { - url = `https://${this.currentServer}`; + url = `https://${currentServer}`; } } else { url = `http://${currentServer}:${this.serverPort}`; if (this.ssl) { - url = `https://${this.currentServer}:${this.serverPort}`; + url = `https://${currentServer}:${this.serverPort}`; } } return `${url}/${this.contextPath}`; From 5a10a5617378bcc81b5de0a2b7773fc110148a58 Mon Sep 17 00:00:00 2001 From: netfoxor Date: Thu, 30 Dec 2021 10:33:25 +0800 Subject: [PATCH 2/2] fix: fix contextPath cannot be set to empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit const configClient = new NacosConfigClient({ serverAddr: '127.0.0.1:8848', contextPath: '', }); 在使用NacosConfigClient时指定了contextPath但还是不生效,通过跟踪代码,发现在调http_agent中如果contenxPath为空,会再设置一次默认值,在创建NacosConfigClient时已经处理过一次(如果contextPath不存在则使用默认值'nacos'),所以我的理解这一步应该不需要了,也要考虑有些服务端进行改造时把contextPath去掉的情况。 --- packages/nacos-config/src/http_agent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nacos-config/src/http_agent.ts b/packages/nacos-config/src/http_agent.ts index 02766fd..40aef69 100644 --- a/packages/nacos-config/src/http_agent.ts +++ b/packages/nacos-config/src/http_agent.ts @@ -71,7 +71,7 @@ export class HttpAgent { } get contextPath() { - return this.configuration.get(ClientOptionKeys.CONTEXTPATH) || 'nacos'; + return this.configuration.get(ClientOptionKeys.CONTEXTPATH) || ''; } get clusterName() { @@ -216,7 +216,7 @@ export class HttpAgent { url = `https://${currentServer}:${this.serverPort}`; } } - return `${url}/${this.contextPath}`; + return `${url}${this.contextPath ? `/${this.contextPath}` : ''}`; } decodeResData(res, method = 'GET') {