chore: monorepo 工作区与开发环境

Bun workspaces + 根 tsconfig、开发用 PostgreSQL compose、.env.example(端口 18456、SK_KEY_ENCRYPTION_SECRET 等)。
This commit is contained in:
2026-10-06 01:30:51 +08:00
parent 4566ce8d58
commit 4c55c3f15f
6 changed files with 1443 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# ── new-api-key-usage · 本地环境变量示例 ──────────────────────────
# 复制为 .env 后填写(.env 已被 .gitignore,勿提交)
# 本服务端口(避开 3000/3001 等常见占用)
PORT=18456
# PostgreSQL 连接串(开发 compose 默认如下)
DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/new_api_key_usage
# 已登记 sk-key 的加密密钥:≥32 字节随机数,base64url。
# 生成示例(PowerShell):
# $r=[Security.Cryptography.RandomNumberGenerator]::Create();$b=New-Object byte[] 32;$r.GetBytes($b);[Convert]::ToBase64String($b)
# ⚠ 入库后不可更换;丢失 = 存量 key_ciphertext 无法解密。与库同等备份。
SK_KEY_ENCRYPTION_SECRET=
# 上游 NewAPI 实例根地址(不是本服务)
NEWAPI_BASE=http://127.0.0.1:8080
# 会话 cookie 是否带 Secure(默认 true)。
# 本地 http://localhost 或 127.0.0.1 调试:现代浏览器可保留 true;
# 局域网 IP / 自定义域名 / 出现「登录后立刻 401」时改为 false。
COOKIE_SECURE=false
# 业务日志级别:debug | info | warning | error | fatal(访问日志另由 hono/logger 输出)
LOG_LEVEL=info
# 空库双通道:可选。用户名与密码同时存在时,首次 setup-state 静默落库;
# 只填一个视为未配置。此后改 env 不改密;改密走管理面表单。
# ADMIN_INIT_USERNAME=
# ADMIN_INIT_PASSWORD=
+10
View File
@@ -13,3 +13,13 @@
.env
.env.*
!.env.example
# 依赖与构建产物
node_modules/
dist/
build/
.turbo/
# 测试与工具
coverage/
*.tsbuildinfo
+1336
View File
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
services:
postgres:
image: postgres:17-alpine
container_name: new-api-key-usage-pg
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: new_api_key_usage
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d new_api_key_usage"]
interval: 5s
timeout: 3s
retries: 10
volumes:
pgdata:
+16
View File
@@ -0,0 +1,16 @@
{
"name": "new-api-key-usage",
"private": true,
"type": "module",
"workspaces": ["apps/*", "packages/*"],
"scripts": {
"test": "bun test",
"typecheck": "tsc -p tsconfig.json --noEmit",
"dev:server": "bun --hot --env-file=.env apps/server/src/index.ts",
"dev:web": "bun --filter @new-api-key-usage/web dev"
},
"devDependencies": {
"@types/bun": "^1.4.2",
"typescript": "^7.0.2"
}
}
+31
View File
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"types": ["bun"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true,
"paths": {
"@new-api-key-usage/core": ["./packages/core/src/index.ts"],
"@new-api-key-usage/db": ["./packages/db/src/index.ts"]
}
},
"include": [
"apps/server/src/**/*.ts",
"apps/server/test/**/*.ts",
"packages/*/src/**/*.ts",
"packages/*/test/**/*.ts",
"packages/*/drizzle.config.ts"
]
}