mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-05-04 22:30:36 +00:00
fix: resolve API_URL config routing conflict with reverse proxies (#191)
Some checks are pending
Development Build / extract-version (push) Waiting to run
Development Build / test-build-regular (push) Blocked by required conditions
Development Build / test-build-single (push) Blocked by required conditions
Development Build / summary (push) Blocked by required conditions
Some checks are pending
Development Build / extract-version (push) Waiting to run
Development Build / test-build-regular (push) Blocked by required conditions
Development Build / test-build-single (push) Blocked by required conditions
Development Build / summary (push) Blocked by required conditions
Move runtime configuration endpoint from /api/runtime-config to /_config to avoid
conflicts with reverse proxies that route all /api/* requests to the FastAPI backend.
This fixes an issue where users with reverse proxies would see port 5055 incorrectly
appended to their API_URL even when explicitly set via environment variable.
Changes:
- Move frontend/src/app/api/runtime-config/route.ts to frontend/src/app/_config/route.ts
- Update config.ts to fetch from /_config instead of /api/runtime-config
- Add troubleshooting documentation for reverse proxy users
- Update all reverse proxy examples to show correct routing (catch-all handles /_config)
- Bump version to 1.0.11
The new /_config endpoint is automatically handled by standard reverse proxy catch-all
rules (location / { proxy_pass http://frontend; }), requiring no additional configuration
for most users.
Fixes issue where API_URL environment variable was being ignored in reverse proxy setups,
causing CORS errors with "Status code: (null)" and incorrect port 5055 being added.
This commit is contained in:
parent
009a7cd71e
commit
fc8a4a0c64
5 changed files with 97 additions and 65 deletions
|
|
@ -117,7 +117,17 @@ http {
|
|||
ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
||||
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
||||
|
||||
# Frontend
|
||||
# API
|
||||
location /api/ {
|
||||
proxy_pass http://api/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Frontend (catch-all - handles /_config automatically)
|
||||
location / {
|
||||
proxy_pass http://frontend;
|
||||
proxy_http_version 1.1;
|
||||
|
|
@ -129,16 +139,6 @@ http {
|
|||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# API
|
||||
location /api/ {
|
||||
proxy_pass http://api/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -201,10 +201,11 @@ services:
|
|||
- "traefik.http.routers.notebook-frontend.tls.certresolver=myresolver"
|
||||
- "traefik.http.services.notebook-frontend.loadbalancer.server.port=8502"
|
||||
|
||||
# API
|
||||
# API (higher priority to match first)
|
||||
- "traefik.http.routers.notebook-api.rule=Host(`notebook.example.com`) && PathPrefix(`/api`)"
|
||||
- "traefik.http.routers.notebook-api.entrypoints=websecure"
|
||||
- "traefik.http.routers.notebook-api.tls.certresolver=myresolver"
|
||||
- "traefik.http.routers.notebook-api.priority=100"
|
||||
- "traefik.http.services.notebook-api.loadbalancer.server.port=5055"
|
||||
networks:
|
||||
- traefik-network
|
||||
|
|
@ -219,11 +220,11 @@ networks:
|
|||
**Caddyfile:**
|
||||
```caddy
|
||||
notebook.example.com {
|
||||
# Frontend
|
||||
reverse_proxy / open-notebook:8502
|
||||
|
||||
# API
|
||||
reverse_proxy /api/* open-notebook:5055
|
||||
|
||||
# Frontend (catch-all - handles /_config automatically)
|
||||
reverse_proxy / open-notebook:8502
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -261,6 +262,36 @@ services:
|
|||
- Ensure your reverse proxy has valid SSL certificates
|
||||
- Mixed content errors (HTTPS frontend trying to reach HTTP API)
|
||||
|
||||
### Frontend adds `:5055` to URL when using reverse proxy (versions ≤ 1.0.10)
|
||||
|
||||
**Symptoms** (only in versions 1.0.10 and earlier):
|
||||
- You set `API_URL=https://your-domain.com`
|
||||
- Browser console shows: "Attempted URL: https://your-domain.com:5055/api/config"
|
||||
- CORS errors with "Status code: (null)"
|
||||
|
||||
**Root Cause**:
|
||||
In versions ≤ 1.0.10, the frontend's config endpoint was at `/api/runtime-config`, which gets intercepted by reverse proxies routing all `/api/*` requests to the backend. This prevented the frontend from reading the `API_URL` environment variable.
|
||||
|
||||
**Solution**:
|
||||
Upgrade to version 1.0.11 or later. The config endpoint has been moved to `/_config` which avoids the `/api/*` routing conflict.
|
||||
|
||||
**Note**: Most reverse proxy configurations with a catch-all rule like `location / { proxy_pass http://frontend; }` will automatically route `/_config` to the frontend without any additional configuration needed.
|
||||
|
||||
**Only if you have issues**, explicitly configure the `/_config` route:
|
||||
|
||||
```nginx
|
||||
# Only needed if your reverse proxy doesn't have a catch-all rule
|
||||
location = /_config {
|
||||
proxy_pass http://open-notebook:8502;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
```
|
||||
|
||||
**Verification**:
|
||||
Check browser console (F12) - should see: `✅ [Config] Runtime API URL from server: https://your-domain.com`
|
||||
|
||||
### How to Debug
|
||||
|
||||
1. **Check browser console** (F12 → Console tab):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue