Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ jobs:

- name: Build
run: pnpm build

- name: Test
run: pnpm test
7 changes: 4 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ pnpm build:worker
# Type checking
pnpm typecheck # Check both packages

# Run worker tests (Vitest)
pnpm test

# Deploy (builds web, then deploys worker with assets)
pnpm deploy
```

No test suite exists in this project.

## Architecture

This is a **pnpm monorepo** with two packages:
Expand All @@ -51,7 +52,7 @@ The worker serves the frontend's static assets from `web/dist/` via the `ASSETS`
- `dashboard.ts` — spending stats, expiry summary
- `admin.ts` — user management, system settings; also manages items per user at `/api/admin/users/:uid/items`
- `notify.ts` — manual notification test trigger
- `setup.ts` — one-time DB initialization via `SETUP_SECRET`
- `setup.ts` — one-time DB initialization via `SETUP_SECRET` (rate-limited, 3/10min per IP); also exposes `GET /api/setup/state` (public setup-page toggle) and `POST /api/admin/setup` (admin-only, no secret). Core setup/migration logic lives in `worker/src/lib/setup.ts`.

**Database** (`worker/src/db/`):

Expand Down
6 changes: 6 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ You can call it again after each upgrade/deploy to run database migrations (migr

> The old `GET /api/setup/<SETUP_SECRET>` URL is deprecated and returns 405. If you ever visited that URL against a deployment, rotate `SETUP_SECRET`, since the secret may have leaked into browser history or access logs.

`POST /api/setup` is rate-limited per source IP: at most 3 requests per 10 minutes, returning `429` beyond that.

The setup page is gated by the `setup_page_enabled` system setting (`'0'` disabled / `'1'` enabled, default `'1'`), editable from the admin panel. It **only affects the setup page** — `POST /api/setup` works regardless of the toggle. The frontend can query the public `GET /api/setup/state` endpoint (no auth) for `{"enabled": true|false}` (returns `true` when not initialized).

A logged-in admin can also run initialization/migrations directly via `POST /api/admin/setup`, without `SETUP_SECRET` (the setup page is provided by the frontend).

### 5. Register Admin

Visit the app homepage and register an account. The first registered user will automatically become the admin.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ curl -X POST https://your-worker.workers.dev/api/setup \

> 旧的 `GET /api/setup/<SETUP_SECRET>` 地址已废弃(返回 405)。如果你曾通过旧 GET 地址访问过部署,建议轮换 `SETUP_SECRET`,因为 secret 可能已泄露到浏览器历史或访问日志中。

`POST /api/setup` 按来源 IP 限流:每 10 分钟最多 3 次,超限返回 `429`。

setup 页面开关由系统设置 `setup_page_enabled` 控制(`'0'` 关闭 / `'1'` 开启,默认 `'1'`),可在管理后台修改。它**只影响 setup 页面**,`POST /api/setup` 无论开关状态都照常工作。前端可调用无需鉴权的公开接口 `GET /api/setup/state` 获取 `{"enabled": true|false}`(未初始化时返回 `true`)。

已登录的管理员也可以直接调用 `POST /api/admin/setup` 完成初始化/迁移,无需 `SETUP_SECRET`(setup 页面由前端提供)。

### 5. 注册管理员

访问应用首页注册账号,第一个注册的用户将自动成为管理员。
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "pnpm --filter web build && pnpm --filter worker build",
"build:web": "pnpm --filter web build",
"build:worker": "pnpm --filter worker build",
"test": "pnpm --filter worker test",
"deploy": "pnpm build:web && node scripts/deploy.mjs",
"typecheck": "pnpm --filter web typecheck && pnpm --filter worker typecheck"
},
Expand Down
Loading
Loading