chore: add .env.example with required configuration templates

This commit is contained in:
2026-02-07 03:49:13 +08:00
parent e8a8ad389c
commit cd9e5f5860
2 changed files with 45 additions and 5 deletions

16
.env.example Normal file
View File

@@ -0,0 +1,16 @@
# Server Port
PORT=3000
# JWT Secret Key (generate a secure random string in production)
JWT_SECRET=your-secret-key-here
# Database URL (SQLite file path)
# Windows format: file:C:/path/to/database.sqlite
# Unix format: file:/path/to/database.sqlite
DATABASE_URL=file:./data/database.sqlite
# Max Request Body Size
MAX_REQUEST_SIZE=10mb
# API Base URL (for frontend)
VITE_API_BASE_URL=/api

View File

@@ -6,9 +6,13 @@
- **NestJS**: 渐进式 Node.js 框架 - **NestJS**: 渐进式 Node.js 框架
- **TypeScript**: 类型安全 - **TypeScript**: 类型安全
- **Prisma**: 现代化 ORM使用 better-sqlite3 适配器)
- **SQLite**: 轻量级数据库 - **SQLite**: 轻量级数据库
- **JWT**: 身份认证 - **better-sqlite3**: 高性能 SQLite 驱动
- **@nestjs/jwt**: JWT 身份认证
- **bcryptjs**: 密码加密 - **bcryptjs**: 密码加密
- **Zod**: 运行时类型验证
- **nestjs-zod**: NestJS 与 Zod 集成
## 项目结构 ## 项目结构
@@ -49,10 +53,20 @@ backend/
## 安装 ## 安装
1. 安装依赖:
```bash ```bash
pnpm install pnpm install
``` ```
2. 配置环境变量:
```bash
cp .env.example .env
```
3. 编辑 `.env` 文件,设置你的配置(特别是 `JWT_SECRET`
## 开发 ## 开发
启动开发服务器(支持热重载): 启动开发服务器(支持热重载):
@@ -89,16 +103,26 @@ pnpm init-db
## 环境变量 ## 环境变量
创建 `.env` 文件: 创建 `.env` 文件(参考 `.env.example`
```env | 变量名 | 说明 | 默认值 |
PORT=3000 | ------------------- | ------------------------ | ----------------------------- |
JWT_SECRET=your-secret-key-here | `PORT` | 服务器端口 | `3000` |
| `JWT_SECRET` | JWT 签名密钥(必须修改) | - |
| `DATABASE_URL` | SQLite 数据库文件路径 | `file:./data/database.sqlite` |
| `MAX_REQUEST_SIZE` | 最大请求体大小 | `10mb` |
| `VITE_API_BASE_URL` | API 基础路径 | `/api` |
**安全提示**:在生产环境中,请务必设置一个强随机字符串作为 `JWT_SECRET`。可以使用以下命令生成:
```bash
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
``` ```
## 默认账户 ## 默认账户
初始化后默认创建的管理员账户: 初始化后默认创建的管理员账户:
- 用户名: admin - 用户名: admin
- 密码: Beifan@2026 - 密码: Beifan@2026