Skip to content

fix(server): respect PLANNOTATOR_SERVER_URL and PLANNOTATOR_HOST env vars#749

Open
buihongduc132 wants to merge 1 commit into
backnotprop:mainfrom
buihongduc132:upstream/fix-server-url-env
Open

fix(server): respect PLANNOTATOR_SERVER_URL and PLANNOTATOR_HOST env vars#749
buihongduc132 wants to merge 1 commit into
backnotprop:mainfrom
buihongduc132:upstream/fix-server-url-env

Conversation

@buihongduc132
Copy link
Copy Markdown

What

All three servers hardcoded http://localhost:{port} for their server URL. No way to override it even though the README documents PLANNOTATOR_SERVER_URL for remote access.

Why

Two real scenarios where hardcoded localhost doesn't work:

  1. Behind a reverse proxy / tunnel — Cloudflare Tunnel, ngrok, Tailscale Funnel. The external URL is different from the listen address. You need to tell the server what URL to advertise.

  2. Binding to a specific network interface — Tailscale IP, LAN IP, etc. You want the browser to open http://100.x.x.x:port not http://127.0.0.1:port.

Changes

packages/server/remote.ts

Added two new exported functions:

  • getServerUrl(port) — Returns the URL for accessing the server.

    • Priority: PLANNOTATOR_SERVER_URLPLANNOTATOR_HOSThttp://127.0.0.1:{port}
    • For remote sessions (0.0.0.0 binding), still advertises localhost since 0.0.0.0 isn't clickable
  • Updated getServerHostname() — Now checks PLANNOTATOR_HOST before falling back to remote/local defaults.

packages/server/index.ts, annotate.ts, review.ts

Replaced hardcoded ``http://localhost:${port}``` with getServerUrl(port) in all three servers.

Testing

5 new tests covering all priority levels and env var combinations.

Backwards Compatibility

100% — when no env vars are set, behavior is identical to before.

…vars

All three servers hardcoded http://localhost:{port} for their server URL.
This broke two real use cases:

1. Running behind a reverse proxy or tunnel (e.g., Cloudflare Tunnel,
   ngrok) where the external URL differs from the listen address.
   PLANNOTATOR_SERVER_URL lets you override the entire URL.

2. Binding to a specific network interface (e.g., Tailscale IP for
   remote access from another machine). PLANNOTATOR_HOST lets you
   set just the hostname while keeping the dynamic port.

getServerUrl() priority:
  1. PLANNOTATOR_SERVER_URL → full URL override
  2. PLANNOTATOR_HOST → hostname override with actual port
  3. Default → http://127.0.0.1:{port} (or http://localhost:{port} for remote)

getServerHostname() now also respects PLANNOTATOR_HOST.
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