Skip to content

后端:setup 限流 + 公开状态接口 + 页面开关 + 管理员免密钥升级接口 - #126

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14da1-595c-7855-9337-5858bb22d6d1
Oct 18, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14da1-595c-7855-9337-5858bb22d6d1

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Rate-limit POST /api/setup to 3 requests per 10 minutes per source IP, counted before the secret check.
  • Add a setup_page_enabled system setting ('0'/'1', default '1') that gates only the setup page, plus a public GET /api/setup/state endpoint for the frontend.
  • Extract the setup/migration logic into a shared runSetup(env) and expose an admin-only POST /api/admin/setup that requires no SETUP_SECRET.

Changes

Setup routes (worker/src/routes/setup.ts, worker/src/lib/setup.ts)

  • POST /api/setup now runs the existing rateLimit middleware (max: 3, window: 600, keyPrefix: "setup"); the constant-time safeEqual secret check is unchanged.
  • New public GET /api/setup/state returns 200 {"enabled": boolean} with no auth and no info leak; it is registered before the GET /api/setup/* 405 catch-all, and returns true when system_settings is absent or the row is missing.
  • Moved schema/DEFAULT_SETTINGS/runMigrations/runSetup into lib/setup.ts, exporting runSetup(env) returning the same shape ({ success: true } / { success: true, alreadyInitialized: true }).

Admin routes (worker/src/routes/admin.ts)

  • Added setup_page_enabled to PUT /api/admin/system/settings allowed keys, accepting only '0'/'1' (other values → 400).
  • New POST /api/admin/setup (behind existing authMiddleware + adminMiddleware) calls runSetup without SETUP_SECRET; failures return 500 and log.

Tests + tooling

  • Introduced a Vitest suite (the repo previously had none) under worker/test/ with in-memory D1/KV mocks and a cloudflare:sockets stub: 20 tests covering rate limiting, state, settings validation, and admin setup auth (admin 200 / user 403 / anonymous 401 / no SETUP_SECRET).
  • Added pnpm test scripts (root + worker) and a Test step to the CI check job.

Docs

  • Documented the rate-limit rule, setup_page_enabled toggle, GET /api/setup/state, and the admin no-secret endpoint in README.md, README.en.md, and CLAUDE.md.

Testing

  • pnpm install --frozen-lockfile ✅
  • pnpm lint ✅ (2 pre-existing warnings unrelated to this change)
  • pnpm format:check ✅
  • pnpm typecheck ✅ (web + worker)
  • pnpm build ✅ (web + worker)
  • pnpm test ✅ — 20/20 passing

No schema changes and no wrangler.toml runtime-config changes; all tables remain scoped by TABLE_PREFIX.

- Rate-limit POST /api/setup (3/10min/IP) and add setup_page_enabled toggle + public GET /api/setup/state
- Extract runSetup to lib/setup.ts; add POST /api/admin/setup (admin-only, no setup secret)
- Add Vitest suite for rate limit, state, settings, and admin setup endpoints

Checkpoint: eiF_GtAjkPXjMA65Cqw_T
@todosdev
todosdev Bot merged commit 264957e into main Oct 18, 2026
1 check passed
@mapxn
mapxn deleted the tds/conv-01a14da1-595c-7855-9337-5858bb22d6d1 branch October 18, 2026 08:59
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.

0 participants