feat: add TCP proxy support for database and cache aliases#161
feat: add TCP proxy support for database and cache aliases#161shige wants to merge 3 commits intovercel-labs:mainfrom
Conversation
|
@shige is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey, love portless! It's been super handy for local dev! I've been wanting to use it with databases and caches (PostgreSQL, MySQL, Redis) too. Since those are raw TCP, they can't go through the hostname-based HTTP proxy, so I put together this PR adding portless alias --tcp . It assigns a dedicated listen port and proxies traffic to the target. list and get are also updated to keep the CLI consistent. This does add some complexity to the daemon for TCP listener lifecycle, but I've tried to handle the common edge cases (bind races, daemon restarts, worktree contexts, etc.). Happy to iterate if the direction seems reasonable, and totally understand if it's more scope than intended. |
Summary
Portless only supported HTTP/HTTPS routing by hostname, so raw TCP services (PostgreSQL, MySQL, Redis, etc.) couldn't be exposed through aliases. This PR adds
portless alias --tcp <name> <port>, which assigns a dedicated listen port in the5500-5999range and proxies traffic to the target. Each alias gets its own port because raw TCP has noHostheader for multiplexing.Changes
portless alias --tcp <name> <port>to register TCP aliases;portless listandportless getreturn the connect address127.0.0.1:<listenPort>tcp-proxy.ts): minimal bidirectionalnetmodule proxy between the listen port and the targetroutes.jsonwith optionaltypeandlistenPortfields; existing HTTP entries are unaffectedaddTcpRoute()uses two-phase locking to avoid holding the file lock during async bind probes, and tracks active listeners intcp-listeners.jsonto preserve daemon-held ports across alias updates127.0.0.1only, and are excluded from HTTP routing and hosts syncTest plan
pnpm --filter portless buildpnpm --filter portless testpnpm lint && pnpm typecheck && pnpm format:checkpsql), MySQL (mysql), Redis (redis-cli) all connect through assigned proxy ports