Add x-app-url header to tunnel requests
This commit is contained in:
parent
eb2e5a4436
commit
70f52a9b55
|
|
@ -686,16 +686,16 @@ toes share my-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
|
||||
import { appUrl } from '@because/toes'
|
||||
|
||||
app.get('/callback', c => {
|
||||
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`)
|
||||
})
|
||||
```
|
||||
|
|
|
|||
|
|
@ -177,6 +177,11 @@ function openTunnel(appName: string, port: number, subdomain?: string, isReconne
|
|||
subdomain,
|
||||
reconnect: false,
|
||||
|
||||
onRequest(req) {
|
||||
const app = getApp(appName)
|
||||
if (app?.tunnelUrl) req.headers['x-app-url'] = app.tunnelUrl
|
||||
},
|
||||
|
||||
onOpen(assignedSubdomain) {
|
||||
hostLog(`Tunnel open: ${appName} -> ${assignedSubdomain}`)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user