You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,14 +17,24 @@ This project is the alternative I wanted: **a simple, free, open-source relay**
17
17
18
18
A nice side-effect: you can keep the **same third-party webhook URL** (pointing at your production app) and **toggle forwarding on/off** with a config change (e.g. `enabled=False`) or by simply connecting/disconnecting the dev client—no redeploy and no “update webhook URL” dance.
19
19
20
+
**Single instance vs multiple:** With one FastAPI instance in production, the default setup works with no extra infrastructure. If you run multiple instances behind a load balancer, add `redis_url` and install the `[redis]` extra so webhook requests routed to any instance still reach your dev client.
21
+
20
22
### Install
21
23
22
24
```
23
25
pip install fastapi-dev-proxy
24
26
```
25
27
28
+
**Multiple instances (load balanced):** If you run more than one FastAPI instance in production (e.g. behind a load balancer), install the optional Redis dependency so webhook requests can reach the dev client no matter which instance receives them:
29
+
30
+
```
31
+
pip install fastapi-dev-proxy[redis]
32
+
```
33
+
26
34
### Server integration
27
35
36
+
**Single instance** (default—no extra infrastructure):
**Multiple instances** (behind a load balancer): Pass `redis_url` so instances coordinate via Redis. The dev client can connect to any instance; webhook requests to any instance are forwarded correctly:
51
+
52
+
```python
53
+
import os
54
+
from fastapi import FastAPI, Response
55
+
from fastapi_dev_proxy.server import RelayManager
56
+
57
+
app = FastAPI()
58
+
relay = RelayManager(
59
+
app=app,
60
+
token="secret",
61
+
enabled=True,
62
+
timeout_seconds=25,
63
+
redis_url=os.environ.get("REDIS_URL"), # e.g. redis://localhost:6379/0
64
+
)
65
+
66
+
@app.post("/webhook/sms")
67
+
asyncdefsms_webhook() -> Response:
68
+
return Response(status_code=200)
69
+
```
70
+
71
+
With `redis_url=None` (the default), behavior is unchanged: single-instance only. Set `redis_url` only when you run multiple instances.
72
+
40
73
If you prefer, you can create the relay first and call `relay.install(app)` later.
41
74
42
75
When installed (default `path_prefix` is `/fastapi-dev-proxy`), the relay registers:
0 commit comments