Skip to content

Fix baseURL double-prefix when request path starts with /#3

Merged
dev-dami merged 4 commits into
masterfrom
copilot/fix-baseurl-ignored-in-axios
Apr 6, 2026
Merged

Fix baseURL double-prefix when request path starts with /#3
dev-dami merged 4 commits into
masterfrom
copilot/fix-baseurl-ignored-in-axios

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

When using axios.create({ baseURL: '/api' }) with a path starting with /, the baseURL was applied twice — producing /api/api/auth/login instead of /api/auth/login — causing a URL parse failure.

Root Cause

src/instance.ts calls buildUrl() to resolve the full URL, then passes the entire instanceConfig (still containing baseURL) to core/request.ts. Since core/request.ts calls buildUrl() again, relative baseURL values got applied a second time. Absolute baseURLs were unaffected because the resulting URL passes isAbsoluteUrl() and is used as-is.

Fix

Strip baseURL and url from instanceConfig before handing off to core/request.ts, since URL resolution is already complete at that point.

// src/instance.ts — before
return request(instanceConfig.url!, instanceConfig, instanceChain);

// after
const { baseURL: _baseURL, url: _url, ...resolvedInstanceConfig } = instanceConfig;
return request(instanceConfig.url!, resolvedInstanceConfig, instanceChain);

Tests

  • test/unit/instance-baseurl.test.ts: stubs global.fetch to assert the exact URL sent — /api/auth/login, not /api/api/auth/login
  • test/axios/compatibility.test.ts: adds an integration case for axios.create with a baseURL containing a path segment and a leading-slash request path

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.example.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js b.com/dev-dami/kiattp/sessions/5761a7d0-5bf0-440b-9347-d3a3f6abbc83 k/_temp/ghcca-node/node/bin/git logs s ost:*;127.0.0.1;--noprofile /home/REDACTED/work/_temp/ghcca-node/node/bin/node --en�� /home/REDACTED/work/_temp/copilot-developer-action-main/dist/indexcredential.helper (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js --global tnet/tools/git user.name (dns block)
  • this-host-does-not-exist-xyz123.test
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js --global 1/x64/bin/node user.name (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions development --conditions node /home/REDACTED/work/kiattp/kiattp/node_modules/tinypool/dist/entry/process.js aseurl.test.ts node_modules/.bin/sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 6, 2026 that may be closed by this pull request
@dev-dami dev-dami marked this pull request as ready for review April 6, 2026 13:31
Copilot AI and others added 2 commits April 6, 2026 13:35
Copilot AI changed the title [WIP] Fix baseURL ignored when request path starts with / Fix baseURL double-prefix when request path starts with / Apr 6, 2026
Copilot AI requested a review from dev-dami April 6, 2026 13:43
Removed comments explaining the stripping of baseURL and url from instanceConfig.
@dev-dami dev-dami merged commit b3867f3 into master Apr 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

axios.create({ baseURL }) ignores baseURL when request path starts with /

2 participants