Skip to content

Commit 782cfc5

Browse files
Merge pull request #86 from uniocjs/dev-groupguanfang
docs: update nest.js section
2 parents fc7f034 + 1665acb commit 782cfc5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/content/nestjs.md

+40
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
# Nest.js 集成
2+
3+
如果您当前有一个`nest.js`项目,您可以很方便从`nest.js`迁移到`unioc`
4+
5+
> [!WARNING]
6+
>
7+
> 目前,`unioc``nest.js`适配器还处于实验阶段,仅支持基础的`Restful` API支持,我们将在接下来的时间里继续完善其他功能。
8+
9+
## 安装
10+
11+
```bash
12+
pnpm i unioc
13+
```
14+
15+
## 使用
16+
17+
更改您的启动器代码为如下:
18+
19+
```ts twoslash
20+
// @noErrors
21+
import process from 'node:process'
22+
import { NestJS } from 'unioc/adapter-nestjs'
23+
import { ExpressApp } from 'unioc/web-express'
24+
import { AppModule } from './app.module'
25+
26+
async function bootstrap() {
27+
// 创建一个 Express 应用
28+
const app = await new ExpressApp()
29+
30+
// 使用 NestJS 适配器,并导入您的程序主模块
31+
app.use(NestJS, {
32+
imports: [AppModule],
33+
} satisfies NestJS.Options)
34+
35+
// 运行这个应用
36+
await app.run(process.env.PORT || 3616)
37+
}
38+
bootstrap()
39+
```
40+
41+
目前,`nest.js`还没有适配`@nestjs/swagger`等这类直接通过修改`bootstrap`来适配的插件,后续将会有规划出一个统一的`swagger`插件。

0 commit comments

Comments
 (0)