自己在用 nestjs+nextjs 搭,感觉好多问题不太好解决,比如 next 中如何在直出时就读到数据库中的数据进行渲染,而不是在前端页面再发起请求拉取。 搭的架子目录结构大概如下:
src
- client // 前端,nextjs
- assets // 前端资源,如 css
- pages // 前端页面
- pageA
- pageB
index.tsx
- server // 后台
- modules
- moduleA
controller.ts
module.ts
service.ts
- moduleB
controller.ts
module.ts
service.ts
- config // 一些前后端都可用到的配置
- utils // 一些前后端都可用到的工具函数
- types // 类型定义
index.ts // 项目启动文件
next-server.ts // next-server