Repository navigation
feat(cli): vercel target reaches plain Postgres without a WebSocket proxy - #698
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
blove
temporarily deployed
to
vercel-preview
September 17, 2026 05:36 — with
GitHub Actions
Inactive
…cket proxy The vercel target's generated stores.mjs used @neondatabase/serverless unconditionally, so running the built function against a local Postgres required an undocumented wsproxy configured through B4_PG_WS_PROXY, whose value had to be a bare host:port. This makes the Vercel variant select a driver per request — B4_PG_DRIVER when set, the neon driver when a proxy is configured or the host is *.neon.tech, and otherwise a pooled pg connection opened through @b4run/postgres-storage/node's new createPostgresPool export — and normalises B4_PG_WS_PROXY on both targets so ws:// and wss:// prefixes are accepted and anything else is rejected by name. The decision lives in a pure module exported from @b4run/cli/fetch and is unit-tested directly; the emitted file is driven against driver doubles for both targets, and a Docker-gated round trip proves the pg path against a real Postgres with no proxy. pg is bundled into the function (~177 KiB unminified) rather than made an optional external, because the Vercel output validator requires a self-contained index.func. Closes #690 Co-Authored-By: Claude Fable 5.1 <[email protected]>
The three MDX pages this branch edits carry recorded source digests in `apps/web/app/seo/lastmod.generated.json`, so editing them makes the manifest stale and `generate-seo-lastmod --check` fails in source-validate. Regenerated with `--as-of 2026-09-17`; only the three edited routes move. Co-Authored-By: Claude Opus 5 <[email protected]>
blove
force-pushed
the
blove/vercel-local-postgres-690
branch
from
September 17, 2026 15:47
1b7bb02 to
07c8db0
Compare
blove
temporarily deployed
to
vercel-preview
September 17, 2026 15:48 — with
GitHub Actions
Inactive
blove
added a commit
that referenced
this pull request
Sep 17, 2026
#698 restructured the generated stores.mjs around selectPostgresDriver and moved the emitted-stores harness into test/helpers/emitted-stores.ts, both in the code this branch rewrites. Resolved by taking main's structure and re-applying this branch's work on top: the naming bindings resolve before the driver is selected (still before any pool is opened), NAMING_STORAGE_STUB joins the shared helper beside the other store stubs, and the new tests use the helper's (appRoot, storesDir, envs) signature. The inline cliStub gained describeConnectionTarget and formatErrorChain, which the emitted file now imports. The edge docs line about per-isolate migration tracking now says per database, schema and prefix, matching the memo key. Co-Authored-By: Claude Opus 5 <[email protected]>
14 of 16 tasks
blove
added a commit
that referenced
this pull request
Sep 17, 2026
Resolves four conflicts against #693 (typed build.targets) and #698 (vercel Postgres driver): - core types.ts and the configuration reference keep main's BuildTargetName union alongside the new build.vercel block. - The targets registry keeps main's Record<BuildTargetName, BuildTarget> alongside the config field on BuildEmitContext. - The SEO lastmod manifest is regenerated rather than hand-merged. Also renames the function path in #698's new "Run the Vercel bundle locally" snippet, which still imported index.func. Co-Authored-By: Claude Opus 5 <[email protected]>
blove
added a commit
that referenced
this pull request
Sep 17, 2026
#698 landed while this branch was open and closed #690: the vercel target's generated stores now select a driver per request, so the built bundle reaches a plain local Postgres over pooled `pg` with no WebSocket proxy at all. The guide documented the proxy as a hard requirement, so that section was rewritten: - the local recipe is now DATABASE_URL plus a bare `node --input-type=module` import, no Docker network and no wsproxy containers; - `B4_PG_WS_PROXY` is described with the forms it actually accepts (host:port, ws://, wss://), as a way to rehearse the Neon path rather than as a precondition, alongside `B4_PG_DRIVER` and the proxy-with-pg configuration error; - the driver detail links to the edge page's new "Database drivers" section instead of restating it; - the fit check no longer claims WebSocket Postgres is required, and the Neon section notes non-Neon hosts get a pooled `pg` connection. Conflicts resolved toward main: configuration.mdx takes main's `BuildTargetName` union wording from #693, which already names both edge targets, and lastmod.generated.json is regenerated. Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Sep 17, 2026
blove
added a commit
that referenced
this pull request
Sep 17, 2026
#695 landed two things this guide needed: - `build.vercel.outDir` / `b4 build --out-dir <dir>`, with the flag winning over the config value, app-root-relative resolution, the rejection of a directory containing the app root, and the error when vercel is not a configured target; - a relaxed output validator. `config.json` now needs version 3 and a route reaching `/index` rather than the exact catch-all, and extra routes and top-level keys are accepted. Together those turn the frontend-composition section from a list of workarounds into a supported flow: stage the runtime tree elsewhere, assemble into `.vercel/output`, and a composed config still validates. The section now says so, and says plainly that the validator runs on what the target stages rather than on what an assembler produces, and that renaming the function off `dest: "/index"` makes the final config the author's responsibility. Also records that the generated stores import `@b4run/postgres-storage/node`, which reaches `pg` through that package's own dependency so an app never declares `pg` itself — the one real gap raised by the session that owns #698. cli.mdx conflicted and takes main's bullet, which covers outDir and the relaxed validator, with a link to this page appended. Co-Authored-By: Claude Opus 5 <[email protected]>
blove
added a commit
that referenced
this pull request
Sep 17, 2026
…708) The "Run the Vercel bundle locally" recipe added in #698 verified nothing, because #694 landed after it. #694 made GET /healthz pure process liveness and added GET /readyz, and the recipe still called /healthz, which never builds the request's stores — so it answered 200 whether or not DATABASE_URL resolved. That is the opposite of the section's purpose: proving the pg fallback reached a plain local Postgres with no WebSocket proxy. Measured on a Vercel fixture built from main, against a real Postgres container: /healthz, reachable database: 200 {"status":"ready"} /healthz, unreachable database: 200 {"status":"ready"} /readyz, reachable database: 200, checkpointer/permissionsStore/threadsStore ok /readyz, unreachable database: 503 not_ready, naming connect ECONNREFUSED The two sample bodies in the page are that run's output. The password in the failing connection string does not appear in the response, which is what the redaction note rests on. Also adds /readyz to the rooted surfaces the runtime owns, a list written before #694 that omitted it. Co-Authored-By: Claude Opus 5 <[email protected]>
This branch was successfully deployed
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.
Closes #690.
What
verceltarget. The generatedstores.mjsnow decides per request which driver opens the pool:B4_PG_DRIVERwhen set; otherwise@neondatabase/serverlesswhenB4_PG_WS_PROXYis set or theDATABASE_URLhost ends in.neon.tech; otherwise a pooledpgconnection. The built function therefore runs against a local Postgres with no proxy. Thehonovariant is unchanged (neon only;B4_PG_DRIVER=pgis refused there because workerd has no TCP).B4_PG_WS_PROXYdocumented and normalised on both targets:host:port,ws://host:port, orwss://host:port(the last keeps TLS on). Any other scheme, a path, or a query is rejected up front with a message naming the variable and the accepted forms, instead of failing inside the driver.selectPostgresDriver/normalizeWsProxyare a pure module exported from@b4run/cli/fetch, so the generated file runs the same code the unit tests do.createPostgresPoolis a new export of@b4run/postgres-storage/node(the existing pool builder made public,'error'listener included). The emitted file reachespgthrough that package's declared dependency, so apps do not have to declarepgand pnpm's strict layout resolves it.B4_PG_WS_PROXY" section plus a "Run the Vercel bundle locally" recipe on the edge deployment page, and rows for the new exports on the two API pages.Bundle size
pgis bundled intoindex.func/index.mjsrather than made an optional external:validateVercelOutputrejects any unresolved bare specifier because the function directory must be self-contained, and an externalpgwould fail exactly the way the issue describes, one hop later. Measured cost of@b4run/postgres-storage/nodeover the main entry is ~177 KiB unminified (21 → 198 KiB), which is well inside Vercel's function limits.Tests
test/postgres-driver.test.ts: 19 unit tests for normalisation and selection (both targets, overrides, conflicts, malformed values).test/vercel-stores.test.ts: drives the emitted Vercelstores.mjsagainst driver doubles — pg for a local host, neon for a Neon host, proxy keeps neon and stripsws://,B4_PG_DRIVERoverrides both ways, malformed values fail before any pool opens, migration pass still once per isolate, and the hono variant never imports the pg builder.test/hono-target.test.ts: new case forws:///wss:/// rejectedhttp://through the emitted file; the stub-driving helpers moved totest/helpers/emitted-stores.tsso both suites share them.test/vercel-target.test.ts: a Docker-gated sibling of the existing round trip that streams Agent Protocol requests through the copied function against plain Postgres with no proxy (passes locally in ~29s;B4_REQUIRE_DOCKER=1makes it mandatory in CI).packages/postgres-storage/test/node-pool.test.ts:createPostgresPoolreturns a realpg.Poolwith the error listener and passes options through.Verified locally on Node 24: full
@b4run/clisuite withB4_REQUIRE_DOCKER=1(162 files, 1845 tests) and@b4run/postgres-storagesuite green;pnpm lint,tscfor both packages, andscripts/check-docs.mjspass. Not released.🤖 Generated with Claude Code