From ad8a1c4489fe37a0566831d0d5e256cc03e44c2b Mon Sep 17 00:00:00 2001 From: GHLandy Date: Thu, 4 Dec 2025 18:34:34 +0800 Subject: [PATCH 1/2] feat: multiple proxy settting support --- package.json | 14 ++++++++------ src/Config.ts | 4 ++-- src/Helper.ts | 17 +++++++++++------ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 25054701..31408228 100644 --- a/package.json +++ b/package.json @@ -201,12 +201,14 @@ "description": "Use local IP as host" }, "liveServer.settings.proxy": { - "type": "object", - "default": { - "enable": false, - "baseUri": "/", - "proxyUri": "http://127.0.0.1:80" - }, + "type": "array", + "default": [ + { + "enable": false, + "baseUri": "/", + "proxyUri": "http://127.0.0.1:80" + } + ], "properties": { "enable": { "type": "boolean", diff --git a/src/Config.ts b/src/Config.ts index 7581e7e7..0ca13f87 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -89,8 +89,8 @@ export class Config { return Config.getSettings('useWebExt') || false; } - public static get getProxy(): IProxy { - return Config.getSettings('proxy'); + public static get getProxy(): IProxy[] { + return Config.getSettings('proxy'); } public static get getHttps(): IHttps { diff --git a/src/Helper.ts b/src/Helper.ts index 625cc68c..3f89d4e7 100644 --- a/src/Helper.ts +++ b/src/Helper.ts @@ -144,15 +144,20 @@ export class Helper { } static getProxySetup() { - const proxySetup = Config.getProxy; - let proxy = [[]]; - if (proxySetup.enable === true) { - proxy[0].push(proxySetup.baseUri, proxySetup.proxyUri); + let proxySetup = Config.getProxy; + if (!Array.isArray(proxySetup)) { + proxySetup = [proxySetup]; } - else { - proxy = null; // required to change the type [[]] to black array []. + const validProxy = proxySetup.filter(item => item.enable); + + if (!validProxy.length) { + return null; } + const proxy = validProxy.map(item => { + return [item.baseUri, item.proxyUri]; + }); + return proxy; } } From eb4dc3dbdf5550da2ecc28709822ce6f6b5e222c Mon Sep 17 00:00:00 2001 From: GHLandy Date: Fri, 5 Dec 2025 09:32:09 +0800 Subject: [PATCH 2/2] fix: fix bot sugguestions --- package.json | 45 ++++++++++++++++++++++++--------------------- src/Config.ts | 6 +++++- src/Helper.ts | 10 +++++++++- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 31408228..84417acf 100644 --- a/package.json +++ b/package.json @@ -209,29 +209,32 @@ "proxyUri": "http://127.0.0.1:80" } ], - "properties": { - "enable": { - "type": "boolean", - "default": false, - "description": "Make it true to enable the feature." - }, - "baseUri": { - "type": "string", - "default": "/", - "pattern": "" + "items": { + "type": "object", + "properties": { + "enable": { + "type": "boolean", + "default": false, + "description": "Make it true to enable the feature." + }, + "baseUri": { + "type": "string", + "default": "/", + "pattern": "" + }, + "proxyUri": { + "type": "string", + "default": "http://127.0.0.1:80", + "pattern": "(^http[s]?://)(.[^(\\|\\s)]+)$" + } }, - "proxyUri": { - "type": "string", - "default": "http://127.0.0.1:80", - "pattern": "(^http[s]?://)(.[^(\\|\\s)]+)$" - } + "required": [ + "enable", + "baseUri", + "proxyUri" + ], + "additionalProperties": false }, - "required": [ - "enable", - "baseUri", - "proxyUri" - ], - "additionalProperties": false, "description": "To Setup Proxy" }, "liveServer.settings.useWebExt": { diff --git a/src/Config.ts b/src/Config.ts index 0ca13f87..bbe22155 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -90,7 +90,11 @@ export class Config { } public static get getProxy(): IProxy[] { - return Config.getSettings('proxy'); + const val = Config.getSettings('proxy'); + if (!val) { + return []; + } + return Array.isArray(val) ? val : [val]; } public static get getHttps(): IHttps { diff --git a/src/Helper.ts b/src/Helper.ts index 3f89d4e7..ab9fc6c3 100644 --- a/src/Helper.ts +++ b/src/Helper.ts @@ -145,10 +145,18 @@ export class Helper { static getProxySetup() { let proxySetup = Config.getProxy; + + // Handle missing/undefined config + if (!proxySetup) { + return null; + } + + // Backward compatibility: old single-object config if (!Array.isArray(proxySetup)) { proxySetup = [proxySetup]; } - const validProxy = proxySetup.filter(item => item.enable); + + const validProxy = proxySetup.filter(item => item && typeof item === 'object' && item.enable); if (!validProxy.length) { return null;