368b1d5b47
Task 12 + Task 7 quality-review carryovers: Part A - password hashing & controlled initial admin: - src/auth/password.ts: hashPassword/verifyPassword over @node-rs/argon2 (napi prebuilt, argon2id default); empty plain rejected at the door - src/scripts/seed-admin.ts: idempotent admin seed (ADMIN_ACCOUNT/ ADMIN_PASSWORD env, walk-up root .env load); existing account -> skip, never overwrites the password; no audit_logs (system op, no actor) - pnpm seed script (build + node dist/scripts/seed-admin.js); .env.example dev defaults admin/admin-secret-change-me - tests: test/password.spec.ts (5), test/seed.spec.ts real-DB idempotency (4) Part B - Task 7 carryovers (all 8): - ApiException(apiCode, message, httpStatus, details?) recognized first by the filter; unmapped-status rule: >=500 -> INTERNAL_ERROR + generic message, <500 -> VALIDATION_FAILED keeping original status (warn-logged) - 5xx/INTERNAL_ERROR responses forced to generic message (leak fix) - pino redact adds req.headers.cookie / res.headers.set-cookie - x-request-id echo capped at 128 chars (fresh UUID beyond, no log) - LOG_LEVEL validated against pino levels at module wiring -> fail fast - shared/ constants (API_PREFIX), request-with-id, log-level (+spec) - jest ts-jest reuses tsconfig.json; unit testMatch includes test/*.spec.ts - build:watch script (no concurrently dep; dev = build:watch + node --watch) api: 35 unit + 10 e2e tests green; root lint/typecheck/test green. Co-Authored-By: Claude Code <noreply@anthropic.com>
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
// services/api/src/main-cn.ts
|
|
// cn-app 部署入口(P1a 仅此一个 API 入口)。构建产物 dist/main-cn.js 由根 dev:api /
|
|
// 生产启动命令运行;env 一律来自进程环境(根 dotenv-cli 注入),此处不读文件。
|
|
import 'reflect-metadata';
|
|
import { type INestApplication } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { Logger } from 'nestjs-pino';
|
|
import { AppCnModule } from './app-cn.module';
|
|
import { API_PREFIX } from './shared/constants';
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
const app = await NestFactory.create<INestApplication>(AppCnModule, {
|
|
bufferLogs: true,
|
|
});
|
|
app.useLogger(app.get(Logger));
|
|
app.setGlobalPrefix(API_PREFIX);
|
|
const corsOrigins = (process.env.CORS_ORIGINS ?? 'http://localhost:5173')
|
|
.split(',')
|
|
.map((origin) => origin.trim())
|
|
.filter((origin) => origin !== '');
|
|
app.enableCors({ origin: corsOrigins });
|
|
const port = Number.parseInt(process.env.PORT ?? '', 10) || 8080;
|
|
await app.listen(port);
|
|
app.get(Logger).log(`api-cn listening on port ${port}`);
|
|
}
|
|
|
|
void bootstrap();
|