Skip to content

fix(server): preserve API mount prefix in server-proxied endpoint URLs#1297

Open
tea-artist wants to merge 1 commit into
opensandbox-group:mainfrom
teableio:upstream/fix-server-proxy-mount-prefix
Open

fix(server): preserve API mount prefix in server-proxied endpoint URLs#1297
tea-artist wants to merge 1 commit into
opensandbox-group:mainfrom
teableio:upstream/fix-server-proxy-mount-prefix

Conversation

@tea-artist

Copy link
Copy Markdown

Problem

The lifecycle API is mounted both bare and under /v1 (main.py includes every router twice), but the use_server_proxy=true endpoint rewrite builds the proxied URL from request.base_url only, dropping the mount prefix the client actually came through:

GET /v1/sandboxes/{id}/endpoints/{port}?use_server_proxy=true
->  "endpoint": "host/sandboxes/{id}/proxy/{port}"     # /v1 lost

On deployments where the server is published behind a path split (e.g. an ingress/reverse proxy routing /v1/* to opensandbox-server while / belongs to another backend), every proxied request then hits the wrong backend: plain HTTP runs into that backend's redirects, and WebSocket handshakes fail outright since WS clients do not follow redirects. This effectively breaks use_server_proxy — the option designed exactly for clients that cannot reach sandbox subdomains directly.

Fix

Derive the mount prefix from the request path and keep it in the rewritten endpoint. server.eip is left verbatim: it is the operator-specified full external base and may already carry its own path prefix (existing test covers that semantic).

Testing

  • Updated the /v1-mounted expectation and added a bare-mount case in test_routes_endpoint_behavior.py
  • Full server suite passes: 1126 passed

The lifecycle API is mounted both bare and under /v1, but the
use_server_proxy endpoint rewrite built the proxied URL from
request.base_url only, dropping the /v1 prefix the client came through.
On shared hosts (path-split deployments where /v1 routes to this server
and / belongs to another backend) proxied HTTP requests hit the wrong
backend's redirects and WebSocket handshakes failed outright.

Derive the mount prefix from the request path and keep it in the
rewritten endpoint. server.eip stays verbatim: it is the operator-
specified full external base and may already carry its own path prefix.

Full server suite: 1126 passed.

Copilot AI 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.

Pull request overview

This PR fixes server-proxied endpoint URL rewriting (use_server_proxy=true) so that it preserves the API mount prefix (e.g. /v1) that the client used to reach the lifecycle API, preventing proxied traffic from being routed to the wrong backend when the server is hosted behind path-based routing.

Changes:

  • Update use_server_proxy URL rewriting to derive and retain the request’s mount prefix when server.eip is not configured.
  • Expand endpoint behavior tests to validate both /v1-mounted and bare-mounted requests produce correctly prefixed proxied URLs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
server/opensandbox_server/api/lifecycle.py Preserves the incoming mount prefix when building server-proxied endpoint URLs (unless server.eip is set).
server/tests/test_routes_endpoint_behavior.py Updates/extends test coverage to assert correct proxied URL rewriting for both /v1 and bare mounts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants