Repository navigation
后端:setup 限流 + 公开状态接口 + 页面开关 + 管理员免密钥升级接口 - #126
Merged
todosdev[bot] merged 1 commit intoOct 18, 2026
Merged
Conversation
- 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
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
POST /api/setupto 3 requests per 10 minutes per source IP, counted before the secret check.setup_page_enabledsystem setting ('0'/'1', default'1') that gates only the setup page, plus a publicGET /api/setup/stateendpoint for the frontend.runSetup(env)and expose an admin-onlyPOST /api/admin/setupthat requires noSETUP_SECRET.Changes
Setup routes (
worker/src/routes/setup.ts,worker/src/lib/setup.ts)POST /api/setupnow runs the existingrateLimitmiddleware (max: 3, window: 600, keyPrefix: "setup"); the constant-timesafeEqualsecret check is unchanged.GET /api/setup/statereturns200 {"enabled": boolean}with no auth and no info leak; it is registered before theGET /api/setup/*405 catch-all, and returnstruewhensystem_settingsis absent or the row is missing.DEFAULT_SETTINGS/runMigrations/runSetupintolib/setup.ts, exportingrunSetup(env)returning the same shape ({ success: true }/{ success: true, alreadyInitialized: true }).Admin routes (
worker/src/routes/admin.ts)setup_page_enabledtoPUT /api/admin/system/settingsallowed keys, accepting only'0'/'1'(other values → 400).POST /api/admin/setup(behind existingauthMiddleware+adminMiddleware) callsrunSetupwithoutSETUP_SECRET; failures return 500 and log.Tests + tooling
worker/test/with in-memory D1/KV mocks and acloudflare:socketsstub: 20 tests covering rate limiting,state, settings validation, and admin setup auth (admin 200 / user 403 / anonymous 401 / noSETUP_SECRET).pnpm testscripts (root + worker) and aTeststep to the CIcheckjob.Docs
setup_page_enabledtoggle,GET /api/setup/state, and the admin no-secret endpoint inREADME.md,README.en.md, andCLAUDE.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 passingNo schema changes and no
wrangler.tomlruntime-config changes; all tables remain scoped byTABLE_PREFIX.