vscode-live-server icon indicating copy to clipboard operation
vscode-live-server copied to clipboard

feat: multiple proxy settting support

Open GHLandy opened this issue 3 weeks ago • 6 comments

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other:

What is the current behavior?

Only Support sigle proxy setting

Issue Number: #2524

What is the new behavior?

Make modification for supporting multiple proxy setting

Does this PR introduce a breaking change?

[x] Yes
[ ] No

liveServer.settings.proxy should change to array from object, example,

{
  "liveServer.settings.proxy": [
    {
      "enable": false,
      "baseUri": "/",
      "proxyUri": "http://127.0.0.1:80"
    }
  ]
}

Other information

N/A

GHLandy avatar Dec 05 '25 01:12 GHLandy

Do you want me to review this PR? Please comment /review .

pantoaibot[bot] avatar Dec 05 '25 01:12 pantoaibot[bot]

/review

GHLandy avatar Dec 05 '25 01:12 GHLandy

PR Summary:

Adds support for multiple proxy entries in configuration and updates runtime handling to return an array of proxy mappings.

  • package.json: changed liveServer.settings.proxy schema from a single object to an array of proxy objects (default is an array with one entry) so users can configure multiple proxies.
  • src/Config.ts: changed getProxy signature to return IProxy[] instead of a single IProxy (reads the new array-shaped setting).
  • src/Helper.ts: rewrote getProxySetup to accept either the old single-object shape or the new array shape (wraps non-array into an array), filters only enabled proxies, and returns an array of [baseUri, proxyUri] pairs or null when none are enabled.
  • Behavior change: proxy configuration now supports multiple entries; only enabled entries are used.
  • Backwards compatibility: Helper.getProxySetup handles older single-object configs at runtime, but the Config.getProxy API/type changed to an array—callers relying on the old single-object type should be reviewed/updated.

Reviewed by Panto AI

pantoaibot[bot] avatar Dec 05 '25 01:12 pantoaibot[bot]

Reviewed up to commit:ad8a1c4489fe37a0566831d0d5e256cc03e44c2b

Additional Suggestion
docs/settings.md, line:99-140 Documentation still shows the old single-object proxy example (see lines 99-140 in docs/settings.md). Update docs to reflect the new array format (example config and explanation) and clearly highlight this breaking change so users can migrate their settings.
* **`liveServer.settings.proxy`:** To enable proxy.
    * *Properties :*
    ```js
    /*
        You can configure multiple proxy rules. Each item maps a baseUri
        (what Live Server serves) to a target proxyUri (your real backend).
    */

    "liveServer.settings.proxy": [
      {
        "enable": true, // set it true to enable this proxy rule
        "baseUri": "/api", // from where you want to proxy
        "proxyUri": "http://localhost:3000/" // the actual url
      },
      {
        "enable": false,
        "baseUri": "/php",
        "proxyUri": "http://localhost/php/"
      }
    ],
    ```

    > **Breaking change:** `liveServer.settings.proxy` used to be a single object.
    > It is now an array of proxy definitions. To migrate, wrap your existing
    > proxy object in an array, for example:
    >
    > ```js
    > // Before
    > "liveServer.settings.proxy": {
    >   "enable": true,
    >   "baseUri": "/",
    >   "proxyUri": "http://localhost/php/"
    > }
    >
    > // After
    > "liveServer.settings.proxy": [
    >   {
    >     "enable": true,
    >     "baseUri": "/",
    >     "proxyUri": "http://localhost/php/"
    >   }
    > ]
    > ```
Others - This PR introduces a breaking change (settings.proxy becomes an array). Ensure release notes and changelog explicitly mention the migration, and consider maintaining graceful handling for the old object format (either at Config.getProxy as suggested above or during startup) so existing users are not immediately broken.
// src/Config.ts
public static get getProxy(): IProxy[] {
    const value = Config.getSettings<IProxy | IProxy[]>('proxy');

    // Backward compatibility: old single-object config
    if (value && !Array.isArray(value)) {
        return [value];
    }

    return value || [];
}

// Additionally, on extension activation (not shown in diff),
// consider logging a deprecation/migration notice if the old
// object-shaped configuration is detected.

Reviewed by Panto AI


Few more points:

  • [CRITICAL_BUG] The settings schema was changed from an object to an array but the schema body still uses "properties" directly. For an array schema you must use "items": { "type": "object", "properties": { ... }, "required": [...], "additionalProperties": false } (and move the required/additionalProperties into items). Current schema is invalid for VSCode and will break settings validation. Update this block to something like:

"liveServer.settings.proxy": { "type": "array", "default": [ { "enable": false, "baseUri": "/", "proxyUri": "http://127.0.0.1:80" } ], "items": { "type": "object", "properties": { ... }, "required": ["enable","baseUri","proxyUri"], "additionalProperties": false } }

Then verify the schema with VSCode (reload) to ensure the settings UI and validation behave correctly.

"liveServer.settings.proxy": {
  "type": "array",
  "default": [
    {
      "enable": false,
      "baseUri": "/",
      "proxyUri": "http://127.0.0.1:80"
    }
  ],
  "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)]+)$"
      }
    },
    "required": [
      "enable",
      "baseUri",
      "proxyUri"
    ],
    "additionalProperties": false
  },
  "description": "To Setup Proxy"
}

pantoaibot[bot] avatar Dec 05 '25 01:12 pantoaibot[bot]

/review

GHLandy avatar Dec 05 '25 01:12 GHLandy

Reviewed up to commit:eb4dc3dbdf5550da2ecc28709822ce6f6b5e222c

Additional Suggestion
Others - Breaking-change impact: you changed the runtime shape of `liveServer.settings.proxy` in package.json to an array. Ensure every other consumer in the codebase (not only Helper.getProxySetup) that reads Config.getProxy has been updated to accept an array. If any other module still expects a single object, runtime errors will occur. Run a global search for usages of `getProxy`/`liveServer.settings.proxy` and update them to handle arrays or ensure Config.getProxy covers all conversions consistently.

Reviewed by Panto AI

pantoaibot[bot] avatar Dec 05 '25 01:12 pantoaibot[bot]