Make base API URL configurable via env var and kwarg#23
Merged
Conversation
Resolves the hard-coded Cloudflare endpoint in Connection and AsyncConnection by accepting a `base_url` keyword argument (highest priority), falling back to the CF_D1_BASE_URL environment variable, and finally the default Cloudflare URL. Users running a local D1 proxy (e.g. `wrangler dev`) can now point the dialect at it without patching source code: - env var: CF_D1_BASE_URL=http://localhost:8787 - engine URL query param: cloudflare_d1://acct:token@db?base_url=http%3A%2F%2Flocalhost%3A8787 - direct kwarg: Connection(..., base_url="http://localhost:8787")
Spins up a minimal in-process HTTP server that mimics the D1 /raw response envelope to verify that base_url kwarg, CF_D1_BASE_URL env var, and ?base_url= connection string query param all correctly redirect requests away from the hard-coded Cloudflare endpoint. No Cloudflare credentials required.
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.
Summary
ConnectionandAsyncConnectionnow accept abase_urlkwarg to override the hard-coded Cloudflare endpointCF_D1_BASE_URLenvironment variable, then the default Cloudflare URLUsage
Closes #22
Test plan
tests/unit/test_dialect.pycovering kwarg, env var, default fallback, and query-param passthroughtests/integration/test_base_url_integration.py— spin up a local HTTP server mimicking the D1/rawresponse format and verify all override mechanisms route requests there (no Cloudflare credentials required)make testpasses (20 unit tests)uv run pytest tests/integration/test_base_url_integration.py -vpasses (5 integration tests)