Skip to content

Add FastAPI fallback proxy to web.py for local development and testing - #13423

Merged
RayBB merged 13 commits into
masterfrom
fastapi-fallback-proxy
Aug 26, 2026
Merged

RayBB merged 13 commits into
masterfrom
fastapi-fallback-proxy

Conversation

@RayBB

@RayBB RayBB commented Aug 25, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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.
@RayBB
RayBB requested a review from cdrini August 25, 2026 16:39
…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
@RayBB RayBB changed the title Add FastAPI fallback proxy to web.py for local development Add FastAPI fallback proxy to web.py for local development and testing Aug 25, 2026
- Add fallback to get_deployment_name() to handle missing web.ctx.host
@RayBB
RayBB force-pushed the fastapi-fallback-proxy branch from e0be2f2 to d1813de Compare August 25, 2026 18:53
RayBB and others added 6 commits August 25, 2026 14:33
- 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>

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 !

Comment thread openlibrary/fastapi/proxy.py Resolved
RayBB and others added 2 commits August 26, 2026 10:39
# 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
RayBB merged commit c22815f into master Aug 26, 2026
6 checks passed
@RayBB
RayBB deleted the fastapi-fallback-proxy branch August 26, 2026 18:27
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>
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants