Add x-app-url header to tunnel requests

This commit is contained in:
Chris Wanstrath 2026-04-04 14:56:29 -07:00
parent eb2e5a4436
commit 70f52a9b55
2 changed files with 8 additions and 3 deletions

View File

@ -686,16 +686,16 @@ toes share my-app
**`toes unshare [name]`** — Stop sharing an app. **`toes unshare [name]`** — Stop sharing an app.
When an app is shared, every proxied request includes an `x-app-url` header set to the app's public tunnel URL (e.g., `https://myapp.toes.space`). When not shared, it's the local URL (e.g., `http://myapp.toes.local`). Every request to your app includes an `x-app-url` header with the app's public-facing URL. When shared, this is the tunnel URL (e.g., `https://myapp.toes.space`). When not shared, it's the local URL (e.g., `http://myapp.toes.local`). This works whether the request arrives through the local proxy or through a tunnel.
Use `appUrl()` from `@because/toes` to read this header: Use `appUrl()` from `@because/toes` to read it — never hardcode your app's URL:
```tsx ```tsx
import { appUrl } from '@because/toes' import { appUrl } from '@because/toes'
app.get('/callback', c => { app.get('/callback', c => {
const url = appUrl(c.req.raw) const url = appUrl(c.req.raw)
// url = "https://myapp.toes.space" if shared, "http://myapp.toes.local" otherwise // "https://myapp.toes.space" when shared, "http://myapp.toes.local" otherwise
return c.redirect(`${url}/done`) return c.redirect(`${url}/done`)
}) })
``` ```

View File

@ -177,6 +177,11 @@ function openTunnel(appName: string, port: number, subdomain?: string, isReconne
subdomain, subdomain,
reconnect: false, reconnect: false,
onRequest(req) {
const app = getApp(appName)
if (app?.tunnelUrl) req.headers['x-app-url'] = app.tunnelUrl
},
onOpen(assignedSubdomain) { onOpen(assignedSubdomain) {
hostLog(`Tunnel open: ${appName} -> ${assignedSubdomain}`) hostLog(`Tunnel open: ${appName} -> ${assignedSubdomain}`)