feat(db): postgres 를 Workers VPC(터널 직결)로 연결 지원 - #89
Merged
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]>
Hyperdrive 를 거치지 않고 wrangler vpc_networks 바인딩(Cloudflare Tunnel)으로 사설망 Postgres 에 직결한다. postgres.js 의 socket 옵션에 VPC 소켓 어댑터를 주입해 드라이버 TCP 를 터널로 라우팅하며, 접속 주소/계정은 DATABASE_URL secret 이 제공한다. VPC 바인딩이 없는 배포(Hyperdrive/직결/Node)는 기존 동작 그대로다. - vpc-socket.ts: postgres.js cf 폴리필과 동일한 이벤트 인터페이스를 VPC binding.connect() 위에 재구현. options.socket 사용 시 postgres.js 가 socket.connect() 를 호출하지 않으므로 팩토리 호출 즉시 연결을 연다. - plaintext TCP 전용(VPC connect 제약) — sslmode 없는 연결 문자열 필요. Co-Authored-By: Claude Fable 5 <[email protected]>
GHSA-mh99-v99m-4gvg (brace-expansion <=5.0.7 DoS), GHSA-r28c-9q8g-f849 (postcss <=8.5.17 source map path traversal) Co-Authored-By: Claude Fable 5 <[email protected]>
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.
요약
Hyperdrive 를 거치지 않고 wrangler
vpc_networks바인딩(Cloudflare Tunnel)으로 사설망 Postgres 에 직결하는 경로를 추가한다. 프로덕션(idp.hyochan.site)은 이미 이 경로로 전환되어 정상 동작 중이다 (/api/health→ok).변경 내용
src/lib/server/db/vpc-socket.ts(신규): postgres.js 의socket옵션에 주입하는 VPC 소켓 어댑터. postgres.js cf 폴리필과 동일한 이벤트 인터페이스를 VPCbinding.connect()위에 재구현해 드라이버 TCP 를 터널로 라우팅한다.options.socket이 있으면socket.connect()를 호출하지 않고 곧바로 startup 메시지를 write 하므로, 팩토리 호출 시점에 즉시 연결을 열고 ready 전 write 는 WritableStream 버퍼링에 맡긴다. 재연결 시에도 팩토리가 다시 호출되어 매번 새 소켓을 연다.connect()는 현재 plaintext TCP 전용 — sslmode 없는 연결 문자열과 함께 사용해야 한다.src/lib/server/db/index.ts: Workers postgres 경로에서platform.env.VPC가 있으면 어댑터를 주입. VPC 바인딩이 없는 배포(Hyperdrive/직결/Node)는 기존 동작 그대로.src/app.d.ts:VPC바인딩 optional 타입 추가.배포 설정(
wrangler.prod.jsonc는 gitignore 대상)은hyperdrive대신:접속 정보는
wrangler secret put DATABASE_URL로 주입한다.검증
"N"응답 수신)select 1성공 (wrangler dev remote 바인딩)/api/health→{"status":"ok","db":"ready"},/login200🤖 Generated with Claude Code