Repository navigation
Add FastAPI fallback proxy to web.py for local development and testing - #13423
Merged
Merged
Conversation
FastAPI (port 8080) now serves as primary entry point locally. Unmatched requests proxy to web.py (port 8081) with proper headers. Fixed redirect URLs to use localhost instead of internal docker URLs. Loop protection prevents infinite proxying. Use http://localhost:8080 for all local development.
FastAPI fallback proxy makes this obsolete.
…ed handler - Extend LOCAL_DEV fallback proxy to testing environment - Remove deprecated_handler.py now that fallback proxy covers both cases - Clean up unused DEPRECATED_PATHS and DeprecatedJSONEndpointHandler classes
- Add fallback to get_deployment_name() to handle missing web.ctx.host
RayBB
force-pushed
the
fastapi-fallback-proxy
branch
from
August 25, 2026 18:53
e0be2f2 to
d1813de
Compare
- Revert compose ports: web 8081->8080, fast_web 8080->18080, OL_URL fast_web->web Homepage showed not found on testing because FastAPI fallback never registered (get_deployment_name() evaluated at startup with empty web.ctx.host) and port swap made web unreachable. - Fix fallback guard: remove startup get_deployment_name() == "testing" check, keep LOCAL_DEV only. Add TODO for per-request host check (request.headers["host"]) which is the correct pattern - see robotstxt:370 and get_deployment_name():17 per-request usage. Co-authored-by: RayBB <ray@archive.org>
The proxy previously buffered the entire request body (await request.body()) and the full upstream response in memory. Stream the request body to web.py as it arrives via request.stream(), and relay the upstream response chunk by chunk with StreamingResponse so neither direction is fully buffered. Use the codebase's cache_per_event_loop shared httpx client, keeping the response alive via closure until its body is consumed. Also rewrite any Location header pointing at the internal web.py host instead of only for 3xx redirects, which previously leaked http://web:8080 on 201 Created responses. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
A streaming proxy can legitimately take a long time (large uploads and downloads), so a fixed wall-clock timeout would kill long-running streams. Set timeout=None (unlimited) on the shared per-event-loop client. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
…est and response bodies
cdrini
approved these changes
Aug 26, 2026
cdrini
left a comment
Collaborator
There was a problem hiding this comment.
Greeeeeaaaattt!!! This is such a big win 😁 This regular expression thing has been very annoying :P
We went through and ensure everything is streamed as much as possible. We tested the site locally:
- cover uploading
- editing
- login
And all worked.
This should be close to working on testing/prod ; but we'll leave in local dev environment for a bit to work out any kinks.
Great work @RayBB !
# Conflicts: # openlibrary/plugins/openlibrary/deprecated_handler.py
_proxy_client returned the TestClient from inside the patch context, so the patch was undone before any request ran. The handler then used the real cache_per_event_loop client and tried to connect to web:8080 — failing CI with ConnectError and, with the unlimited timeout, taking ~75s per test. Make _proxy_client a context manager so the patch covers the request, and move raise_server_exceptions to the TestClient constructor (it is not a per-request kwarg). Test suite drops from minutes to 0.07s. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
RayBB
added a commit
that referenced
this pull request
Aug 26, 2026
Follow up on #13423: FastAPI is now the primary local-dev entry point on port 8080, proxying unmatched requests to web.py, and deprecated_handler.py was deleted. Update the AI guide, AGENTS.md, and a FastAPI docstring plus the FastAPI auth integration test that still pointed at the old 18080 port. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
2 tasks
Closed
7 tasks
1 task
mekarpeles
added a commit
that referenced
this pull request
Oct 8, 2026
…13839) First, decision-free slice of the #13820 consolidation fixes Ray listed in #13835: - CONTRIBUTING: two rules. (1) No developer-machine-specific docs — absolute home paths (/Users/you/…), personal checkout locations, or "works on my box" setup; a per-developer workaround may be described as a limitation but never committed as a path-specific recipe. (2) The in-repo docs/ tree is the single source of truth; the external openlibrary-kb repo is not canonical. Noted that all-developer / agent-home conventions will migrate to .pam. - Fix the wrong dev-port facts (group 1), verified against compose.override (FastAPI publishes host 8080 in dev), compose.production (web.py 8080, FastAPI 18080) and openlibrary/fastapi/proxy.py: in dev FastAPI is the single host-facing entry on 8080 and proxies unmatched routes to web.py; the 8080/18080 split was swapped in #13423 and now applies only in production. Touches docs/core/README.md (two places) and docs/features/activity-feed.md (which also wrongly told readers to pass a separate FastAPI origin locally). - Fix the stale OPDS link in docs/search/index.md (pointed outside the repo at pm/workflows/opds-system.md) to the in-repo docs/opds/README.md. - Remove the client-and-bots "Note on Local Availability" section: a machine path plus ingest/scratch narration (raw/openlibrary-docs-ai, "add to cq"), which CONTRIBUTING already excludes. Follow-ups (separate PRs, per the issue's answered decisions): restore the dropped tag-system and design-guide content from 2148484^; convert [[wikilinks]] to relative links; external openlibrary-kb page links tracked separately. Co-authored-by: Michael E. Karpeles (Mek) <michael.karpeles@gmail.com>
Sanket17052006
pushed a commit
to Sanket17052006/openlibrary
that referenced
this pull request
Oct 8, 2026
…chive#13835) First, decision-free slice of the internetarchive#13820 consolidation fixes Ray listed in internetarchive#13835: - CONTRIBUTING: two rules. (1) No developer-machine-specific docs — absolute home paths (/Users/you/…), personal checkout locations, or "works on my box" setup; a per-developer workaround may be described as a limitation but never committed as a path-specific recipe. (2) The in-repo docs/ tree is the single source of truth; the external openlibrary-kb repo is not canonical. Noted that all-developer / agent-home conventions will migrate to .pam. - Fix the wrong dev-port facts (group 1), verified against compose.override (FastAPI publishes host 8080 in dev), compose.production (web.py 8080, FastAPI 18080) and openlibrary/fastapi/proxy.py: in dev FastAPI is the single host-facing entry on 8080 and proxies unmatched routes to web.py; the 8080/18080 split was swapped in internetarchive#13423 and now applies only in production. Touches docs/core/README.md (two places) and docs/features/activity-feed.md (which also wrongly told readers to pass a separate FastAPI origin locally). - Fix the stale OPDS link in docs/search/index.md (pointed outside the repo at pm/workflows/opds-system.md) to the in-repo docs/opds/README.md. - Remove the client-and-bots "Note on Local Availability" section: a machine path plus ingest/scratch narration (raw/openlibrary-docs-ai, "add to cq"), which CONTRIBUTING already excludes. Follow-ups (separate PRs, per the issue's answered decisions): restore the dropped tag-system and design-guide content from 2148484^; convert [[wikilinks]] to relative links; external openlibrary-kb page links tracked separately.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think it's about time that we do this. We've had a few issues in local dev lately where APIs weren't added to the deprecated path handler and it's just really a pain in the neck to keep up that code. So it's better to just start doing it this way.
Next we'll want to enable this for testing.
FastAPI (port 8080) now serves as primary entry point locally. Unmatched requests proxy to web.py (port 8081) with proper headers. Fixed redirect URLs to use localhost instead of internal docker URLs. Loop protection prevents infinite proxying.
Use http://localhost:8080 for all local development.