Skip to content

fork 友善化部署:wrangler.toml 佔位值、去硬編、slash 後台按鈕、雙路徑 DEPLOY.md#2

Merged
poterpan merged 14 commits into
mainfrom
deploy/fork-friendly-deploy
Jun 7, 2026
Merged

fork 友善化部署:wrangler.toml 佔位值、去硬編、slash 後台按鈕、雙路徑 DEPLOY.md#2
poterpan merged 14 commits into
mainfrom
deploy/fork-friendly-deploy

Conversation

@poterpan

@poterpan poterpan commented Jun 7, 2026

Copy link
Copy Markdown
Owner

背景

讓其他開發者 fork 後能輕鬆部署到自己的 Cloudflare,並清除 repo 內所有 owner 正式值。參考 miantiao-me/Sink 的「fork → 後台連 Git 自動部署」模式,同時 100% 保留純 CLI wrangler deploy。設計與計畫經 Codex 獨立複核。

  • 設計 spec:docs/superpowers/specs/2026-06-07-fork-friendly-deploy-design.md
  • 實作計畫:docs/superpowers/plans/2026-06-07-fork-friendly-deploy.md

改了什麼

  • wrangler.toml 佔位值:route/vars/database_id 改佔位 + 指引註解;移除已停用、會洩 owner email 的 ACCESS_ALLOWED_EMAILS。runtime 設定維持以 wrangler.toml 為單一真相來源(後台 env var 是 build 期、到不了 runtime)。
  • 去除前端硬編 owner 網域
    • web/src/api.ts:移除 VITE_API_BASE 未設時靜默 fallback 到 owner worker;改 fail-loud
    • admin upload-link:worker 用 WEB_ORIGIN 組完整 URL 回傳(WEB_ORIGIN 未設回 500),admin 直接用,移除寫死的 pay.panspace.dev
  • slash 指令註冊後台按鈕:新增 Access 保護的 POST /admin/discord/register-commands(沿用既有 registerGuildCommands helper、payload 取自 commands.ts、guild id 取自 settings)+ 設定頁按鈕。零 CLI forker 可用;pnpm register 腳本保留給 CLI。
  • migration 併進 deploy:worker deploy = wrangler d1 migrations apply chippot-db --remote && wrangler deploy(idempotent),CLI 與 Workers Builds 共用。
  • DEPLOY.md 重寫雙路徑:路徑一(後台 + Git,零本機工具)/路徑二(CLI,保留);新增 secret/var 分層表、VITE_API_BASE 雞生蛋順序、同源 admin route 設定順序。
  • 清理:README 架構範例改 example.comdocs/setup-checklist.md(owner 內部一次性建置檔)改 gitignore。

驗證(CI 條件,無 .dev.vars)

  • pnpm -r typecheck
  • pnpm -r test161 passed (31 files) ✅(新增 upload-link url、WEB_ORIGIN 500、slash 註冊 ×2 等測試)
  • pnpm -r build(web+admin)✅
  • 公開(已追蹤)檔 owner 值掃描:全乾淨(設計/計畫文件合理保留 before/after 描述)

流程

每個 Task 經 implementer → spec 合規審查 → 程式品質審查(含修正迴圈),最後整體 review。整體 review 另抓出並修掉幾個跨任務文件一致性缺口(CLI register 的 .dev.vars 前置、README deploy 指令、過時 var 列表)。

待部署階段處理(非本 PR 阻擋項)

  • D1 token 實機驗證:Workers Builds 的 CI token 是否具 D1 寫權限可跑 --remote migration —— 需在 owner 帳號實測;不足則退回 migration 偶發手動(已記於 spec §7)。
  • owner 本機 wrangler.toml:本機工作檔已被改為佔位值(committed 版正確);owner 純 CLI 部署前需把真實值還原到本機(skip-worktree 仍設著,不會進 commit)。

🤖 Generated with Claude Code

poterpan added 14 commits June 7, 2026 18:44
Brainstormed design for making forks easy to deploy (Sink-style Git integration)
while preserving the full wrangler CLI path. Covers: wrangler.toml placeholders +
owner-value cleanup, removing two hardcoded owner URLs in the frontends, a slash-
command-registration admin button, Workers Builds + Pages Git deploy with migrations
folded into the deploy script, secret/var layering, and a dual-path DEPLOY.md rewrite.
Decisions captured from the brainstorming session; Codex-reviewed assessment incorporated.
Task-by-task TDD plan from the design spec: wrangler.toml placeholders, remove two
hardcoded owner URLs (web api.ts fail-loud, admin upload-link via WEB_ORIGIN),
slash-registration admin button + route, migrations folded into deploy, dual-path
DEPLOY.md rewrite. Includes per-task tests, verification commands, and spec coverage check.
Make the repo fork-safe: routes/vars/database_id become placeholders with
guidance comments; remove ACCESS_ALLOWED_EMAILS (the code path is disabled —
Access policy is the real allowlist — so it only leaked an email). Also
genericize two cosmetic panspace.dev references (index.ts comment, test title).
Owner keeps real values locally via git update-index --skip-worktree.
Task 1 code review found README.md/README.zh-TW.md still reference admin.panspace.dev,
and the final verification grep both missed root READMEs and would self-match the
design docs. Add a README-cleanup task and scope the grep to exclude docs/superpowers
and the owner-internal setup-checklist.md.
…omain

The admin 'copy upload link' feature hardcoded https://pay.panspace.dev. Have the
worker return a full url built from WEB_ORIGIN; the admin SPA uses it verbatim, so
a fork's links point at the fork's own domain.
Remove the hardcoded fallback to the owner's worker URL. A fork that forgets to set
VITE_API_BASE at build time now errors immediately instead of silently routing the
public payment page to the upstream backend.
Add an Access-protected POST /admin/discord/register-commands that PUTs the three
guild commands via the existing registerGuildCommands helper (app id from vars,
guild id from settings, bot token from the runtime secret), plus a Settings-page
button. Lets zero-CLI forkers register slash commands; the pnpm register script
stays for CLI users.
deploy now runs 'wrangler d1 migrations apply chippot-db --remote && wrangler deploy'
so both CLI and Workers Builds apply pending migrations before deploying (idempotent:
wrangler tracks applied migrations).
Primary path: fork + edit wrangler.toml placeholders in the GitHub web editor +
connect Workers Builds & two Pages projects + set secrets in the dashboard — no
local toolchain. Secondary path: the existing wrangler CLI flow, preserved. Adds a
secret/var layering table, migration-in-deploy notes, and same-origin route ordering.
…ructive-migration caveat

Address doc-quality review: list GitHub account as a Path 1 prerequisite; drop the
stray 'cd packages/worker' in the CLI slash-register step (pnpm --filter runs from
root); forward-reference the destructive-migration caveat from the Path 1 update
summary; clarify VITE_API_BASE persists across Pages builds.
Replace admin.panspace.dev with admin.example.com in the README architecture
sections so the public repo carries no owner production domain.
- DEPLOY.md §7: document that the CLI register script needs .dev.vars
  (DISCORD_BOT_TOKEN/APPLICATION_ID/GUILD_ID); note the dashboard button needs
  discord_guild_id set (step 8) first.
- README quick-ref: use 'pnpm --filter @chippot/worker deploy' (migrations+deploy)
  instead of the old two-step; note register prerequisites.
- README: drop the removed ACCESS_ALLOWED_EMAILS from the vars list.
…up notes)

It is an owner-specific build-time Q&A artifact (guild/channel ids, Access team
domain) superseded by DEPLOY.md — not useful to forkers and the last owner-value
leak in the public repo. Stop tracking it (local copy preserved), alongside the
already-ignored docs/deploy-state.md.
@poterpan poterpan merged commit 26cd093 into main Jun 7, 2026
2 checks passed
@poterpan poterpan deleted the deploy/fork-friendly-deploy branch June 7, 2026 12:19
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.

1 participant