Skip to content

Commit 0da6427

Browse files
committed
1.
1 parent 0edf332 commit 0da6427

File tree

5 files changed

+375
-0
lines changed

5 files changed

+375
-0
lines changed

src/.vuepress/sidebar.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export default sidebar({
55
"/youlai-boot/": "structure",
66
"/vue-uniapp-template/": "structure",
77
"/youlai-mall/": "structure",
8+
"/youlai-nest/": "structure",
89
});
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: 项目启动
3+
icon: play
4+
dir:
5+
collapsible: false
6+
expanded: false
7+
order: 1
8+
link: true
9+
category:
10+
- 项目启动
11+
---
12+
13+
## 环境准备
14+
15+
在开始之前,请确保你的开发环境满足以下要求:
16+
17+
1. **Node.js 环境**
18+
```bash
19+
# 检查 Node.js 版本(需要 >= 18.x)
20+
node --version
21+
```
22+
23+
2. **MongoDB 数据库**
24+
- 安装 MongoDB(>= 7.x)
25+
- 启动 MongoDB 服务
26+
```bash
27+
# macOS 使用 brew 安装
28+
brew install mongodb-community
29+
brew services start mongodb-community
30+
```
31+
32+
3. **Redis 服务**
33+
- 安装 Redis(>= 7.x)
34+
- 启动 Redis 服务
35+
```bash
36+
# macOS 使用 brew 安装
37+
brew install redis
38+
brew services start redis
39+
```
40+
41+
4. **pnpm 包管理器**
42+
```bash
43+
# 全局安装 pnpm
44+
npm install -g pnpm
45+
```
46+
47+
## 快速开始
48+
49+
### 1. 克隆项目
50+
```bash
51+
git clone https://gitee.com/youlaiorg/youlai-nest.git
52+
cd youlai-nest
53+
```
54+
55+
### 2. 安装依赖
56+
```bash
57+
pnpm install
58+
```
59+
60+
### 3. 配置环境变量
61+
62+
1. 复制环境变量模板文件
63+
```bash
64+
cp .env.example .env
65+
```
66+
67+
2. 修改 `.env` 文件中的配置:
68+
```env
69+
# MongoDB配置
70+
MONGODB_URI=mongodb://localhost:27017/youlai
71+
72+
# Redis配置
73+
REDIS_HOST=localhost
74+
REDIS_PORT=6379
75+
76+
# JWT配置
77+
JWT_SECRET=your-secret-key
78+
JWT_EXPIRES_IN=7d
79+
80+
# 阿里云OSS配置(如需使用文件上传功能)
81+
OSS_REGION=oss-cn-hangzhou
82+
OSS_ACCESS_KEY_ID=your-access-key
83+
OSS_ACCESS_KEY_SECRET=your-secret-key
84+
OSS_BUCKET=your-bucket
85+
```
86+
87+
### 4. 初始化数据库
88+
89+
1. 导入初始数据(在 mongodb 目录下)
90+
```bash
91+
mongorestore -d youlai ./mongodb/
92+
```
93+
94+
95+
### 5. 启动项目
96+
97+
开发模式
98+
```bash
99+
pnpm run start:dev
100+
```
101+
102+
生产模式
103+
```bash
104+
# 构建项目
105+
pnpm run build
106+
107+
# 启动服务
108+
pnpm run start:prod
109+
```
110+
111+
### 6. 访问服务
112+
113+
- 接口文档:http://localhost:8989/apiDoc
114+
- 默认管理员账号:admin
115+
- 默认密码:123456
+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
---
2+
title: 项目配置
3+
icon: config
4+
dir:
5+
collapsible: false
6+
expanded: false
7+
order: 2
8+
link: true
9+
category:
10+
- 项目配置
11+
---
12+
13+
# 项目配置说明
14+
15+
本文档介绍 youlai-nest 项目的配置方式和相关参数说明。
16+
17+
## 配置文件
18+
19+
youlai-nest 使用多种配置文件管理不同环境的配置:
20+
21+
- `.env`: 默认环境配置
22+
- `.env.development`: 开发环境配置
23+
- `.env.production`: 生产环境配置
24+
- `.env.test`: 测试环境配置
25+
26+
## 核心配置参数
27+
28+
### 基础配置
29+
30+
## 环境变量配置
31+
32+
youlai-nest 使用 `.env` 文件进行环境配置,主要配置项包括:
33+
34+
### MongoDB 配置
35+
36+
```env
37+
# MongoDB连接URI
38+
MONGODB_URI=mongodb://localhost:27017/youlai
39+
```
40+
41+
### Redis 配置
42+
43+
```env
44+
# Redis主机地址
45+
REDIS_HOST=localhost
46+
# Redis端口
47+
REDIS_PORT=6379
48+
# Redis密码(如果有)
49+
REDIS_PASSWORD=
50+
```
51+
52+
### JWT 配置
53+
54+
```env
55+
# JWT密钥
56+
JWT_SECRET=your-secret-key
57+
# JWT过期时间
58+
JWT_EXPIRES_IN=7d
59+
```
60+
61+
### 阿里云 OSS 配置
62+
63+
```env
64+
# OSS区域
65+
OSS_REGION=oss-cn-hangzhou
66+
# OSS访问密钥ID
67+
OSS_ACCESS_KEY_ID=your-access-key
68+
# OSS访问密钥密码
69+
OSS_ACCESS_KEY_SECRET=your-secret-key
70+
# OSS存储桶名称
71+
OSS_BUCKET=your-bucket
72+
```
73+
74+
## 应用配置
75+
76+
通过 NestJS 的 `ConfigModule` 访问配置:
77+
78+
```typescript
79+
import { ConfigModule, ConfigService } from '@nestjs/config';
80+
81+
@Module({
82+
imports: [
83+
ConfigModule.forRoot({
84+
isGlobal: true,
85+
envFilePath: '.env',
86+
}),
87+
// 其他模块...
88+
],
89+
})
90+
export class AppModule {}
91+
```
92+
93+
在服务中使用配置:
94+
95+
```typescript
96+
import { Injectable } from '@nestjs/common';
97+
import { ConfigService } from '@nestjs/config';
98+
99+
@Injectable()
100+
export class AppService {
101+
constructor(private configService: ConfigService) {
102+
// 获取配置值
103+
const mongoUri = this.configService.get<string>('MONGODB_URI');
104+
}
105+
}
106+
```
107+
108+
## Swagger API 文档配置
109+
110+
`main.ts` 中配置 Swagger:
111+
112+
```typescript
113+
import { NestFactory } from '@nestjs/core';
114+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
115+
import { AppModule } from './app.module';
116+
117+
async function bootstrap() {
118+
const app = await NestFactory.create(AppModule);
119+
120+
// Swagger文档配置
121+
const config = new DocumentBuilder()
122+
.setTitle('有来后台管理系统API')
123+
.setDescription('基于NestJS的后台管理系统API文档')
124+
.setVersion('1.0')
125+
.addBearerAuth()
126+
.build();
127+
const document = SwaggerModule.createDocument(app, config);
128+
SwaggerModule.setup('apiDoc', app, document);
129+
130+
await app.listen(8989);
131+
}
132+
bootstrap();
133+
```
134+
135+
## 跨域配置
136+
137+
`main.ts` 中启用跨域:
138+
139+
```typescript
140+
import { NestFactory } from '@nestjs/core';
141+
import { AppModule } from './app.module';
142+
143+
async function bootstrap() {
144+
const app = await NestFactory.create(AppModule);
145+
146+
// 启用CORS
147+
app.enableCors();
148+
149+
await app.listen(8989);
150+
}
151+
bootstrap();
152+
```
153+
154+
## 全局管道配置
155+
156+
添加全局验证管道:
157+
158+
```typescript
159+
import { NestFactory } from '@nestjs/core';
160+
import { ValidationPipe } from '@nestjs/common';
161+
import { AppModule } from './app.module';
162+
163+
async function bootstrap() {
164+
const app = await NestFactory.create(AppModule);
165+
166+
// 添加全局验证管道
167+
app.useGlobalPipes(new ValidationPipe({
168+
whitelist: true,
169+
transform: true,
170+
}));
171+
172+
await app.listen(8989);
173+
}
174+
bootstrap();
175+
```
176+
177+
## 全局前缀配置
178+
179+
配置API全局前缀:
180+
181+
```typescript
182+
import { NestFactory } from '@nestjs/core';
183+
import { AppModule } from './app.module';
184+
185+
async function bootstrap() {
186+
const app = await NestFactory.create(AppModule);
187+
188+
// 设置全局前缀
189+
app.setGlobalPrefix('api');
190+
191+
await app.listen(8989);
192+
}
193+
bootstrap();
194+
```
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: 开发指南
3+
icon: paper-plane
4+
dir:
5+
order: 3
6+
collapsible: false
7+
expanded: true
8+
link: true
9+
category:
10+
- 用户指南
11+
---
12+
13+
14+
## 目录

src/youlai-nest/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: 项目介绍
3+
icon: info
4+
dir:
5+
collapsible: false
6+
expanded: false
7+
order: 1
8+
link: true
9+
category:
10+
- 指南
11+
---
12+
13+
# youlai-nest
14+
15+
<div align="center">
16+
<img src="https://img.shields.io/badge/nestjs-%23E0234E.svg?style=for-the-badge&logo=nestjs&logoColor=white" alt="NestJS"/>
17+
<img src="https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white" alt="MongoDB"/>
18+
<img src="https://img.shields.io/badge/redis-%23DD0031.svg?style=for-the-badge&logo=redis&logoColor=white" alt="Redis"/>
19+
<img src="https://img.shields.io/badge/JWT-black?style=for-the-badge&logo=JSON%20web%20tokens" alt="JWT"/>
20+
<img src="https://img.shields.io/badge/-Swagger-%23Clojure?style=for-the-badge&logo=swagger&logoColor=white" alt="Swagger"/>
21+
</div>
22+
23+
## 项目介绍
24+
25+
youlai-nest 是一个基于 NestJS 框架开发的后台管理系统,采用了现代化的技术栈和最佳实践。本项目提供了完整的权限管理功能,包括用户管理、角色管理、菜单管理等核心功能。
26+
27+
## 功能特性
28+
29+
- 🔐 完整的 RBAC 权限管理
30+
- 📝 MongoDB 数据库支持
31+
- 🚀 Redis 缓存集成
32+
- 📁 阿里云 OSS 文件存储
33+
- 📚 Swagger API 文档
34+
- 🔒 JWT 身份认证
35+
- 🎨 优雅的项目结构
36+
37+
## 文档导航
38+
39+
- [项目启动](./1_项目启动/README.md)
40+
- [项目配置](./2_项目配置/README.md)
41+
- [开发指南](./3_开发指南/README.md)
42+
43+
## 技术支持
44+
45+
- 项目文档:https://doc.youlai.tech
46+
- 问题反馈:https://gitee.com/youlaiorg/youlai-nest/issues
47+
- 交流群:关注公众号【有来技术】获取群二维码
48+
49+
## 许可证
50+
51+
[MIT](LICENSE) © 有来技术团队

0 commit comments

Comments
 (0)