Skip to content

fix(server-sdk): keep the base path of the server URL in API requests - #742

Open
ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/twirp-keep-base-path
Open

ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/twirp-keep-base-path

Conversation

@ANDROIDHASSAN

Copy link
Copy Markdown

TwirpRpc.request builds the request URL with new URL(path, current). The Twirp path starts with / (/twirp/livekit.RoomService/ListRooms), so it replaces any path on the host instead of being appended to it. A server reached under a path, e.g. behind a reverse proxy at https://example.com/livekit, is called at https://example.com/twirp/...:

$ node -e 'console.log(new URL("/twirp/livekit.RoomService/ListRooms", "https://example.com/livekit").href)'
https://example.com/twirp/livekit.RoomService/ListRooms

The Go server SDK hands the URL to the generated Twirp client, which appends /twirp/... to it, and the Python server SDK keeps the base path too (livekit/python-sdks#861). This brings the Node SDK in line.

The path is now appended to the host's own path (twirpUrl), dropping any query string or fragment on the host. Failover is unchanged: fallback regions are bare origins, so a retry goes to https://<region>/twirp/....

Tests in TwirpRPC.test.ts (request url):

  • the base path is kept for https://example.com/livekit, with a trailing slash, and for a wss:// URL; a custom prefix works with or without a leading slash; a query string or fragment on the host is dropped. These fail on main (the base path is missing) and pass now. A host without a path gives the same URL as before.
  • a failover attempt goes to the region origin while the first attempt keeps the base path.

vitest run src passes in the node, edge-runtime and happy-dom environments (51 tests); eslint, prettier --check and tsc --noEmit pass. A changeset is included (patch). The changeset notes the one behaviour change: a URL that carries a path the server does not serve the API under should drop it.

new URL(path, host) with the absolute Twirp path replaced any path on the
host, so a server behind a reverse proxy at https://example.com/livekit
was called at https://example.com/twirp/... Append the Twirp path to the
host's own path instead, as the Go and Python server SDKs do.
@changeset-bot

changeset-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ef095c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
livekit-server-sdk Patch
agent-dispatch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

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.

1 participant