3 Star 129 Fork 13

jsfront / nest-admin-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Nest在代码组织方式上借鉴了ng的方式,在底层上默认了Express的基础上可配置Fastify的这种灵活方式,满足多种选择。天生就以Typescript为类型约束,很适合中大型项目的开发。在配以管道、守卫、拦截器、装饰器等等理念使他与其它Node框架拉开了质的距离,所以这次我们采用他做为API的开发框架,整体开发下来的感觉还是比较符合预期,简单说是越开发越喜欢的感觉。

3.1 基本介绍

async function bootstrap() {
  // 热更新
  if (module.hot) {
    module.hot.accept()
    module.hot.dispose(() => app.close())
  }
}
  • 为防止恶意请求,增加了单一IP的单位时间内请求数的限制。
// 设置访问频率
app.use(
    rateLimit({
      windowMs: 15 * 60 * 1000, // 15分钟
      max: 1000, // 限制15分钟内最多只能访问1000次
    }),
)
  • 日常的文档开发由 @nestjs/swagger 这个包提供 配置生效之后,加入@ApiModelProperty()即可在预览的文档中生效。比如:
import { ApiModelProperty } from '@nestjs/swagger';
export class CreateCatDto {
  @ApiModelProperty()
  readonly name: string;
  
  @ApiModelProperty()
  readonly breed: string;
}

3.2 技术栈

技术 说明 官网
Nest 更优雅的node.js 框架 https://docs.nestjs.com/
Mysql 数据库服务 https://www.mysql.com/cn/
Typeorm Orm https://typeorm.io/
@nestjs/jwt JWT https://github.com/nestjs/jwt
class-validator 数据验证 https://github.com/typestack/class-validator

3.3 文件结构

├─config // 配置文件
├─dist // 打包文件
├─entities // 生成实体文件
├─public // 静态资源
  └─uploads // 上传文件
├─src
  ├─common // 公共文件
    └─logger
  ├─config // 配置文件
  ├─interface // TS文件
  ├─modules // 业务文件
    ├─app
    ├─article
    ├─auth
    ├─category
    ├─common
    ├─file
    ├─menu
    ├─nav
    ├─role
    ├─tags
    └─user
  └─shared // 核心文件
      ├─constants
      ├─core
        ├─decorator
        ├─exception
        ├─filters
        └─interceptors
      ├─transformer
      └─utils
└─test

3.4 如何在本地运行

根目录下运行 npm install,然后运行 npm run dev

// 切换环境
nvm install 16.0.0
nvm use 16.0.0

// 安装依赖
npm install

// 启动项目
npm start

// 清除 node_modules
npm run clean

// 全局安装 rimraf 之后方可使用
npm i rimraf -g

// 清除 node_modules 重新安装依赖
// 等同于 npm run clean && npm install
npm run reinstall

3.5 如何上线发布

3.5.1 打包
$ cd nest-admin-api
$ npm run build

然后上传 nest-admin-api\dist目录中的文件,然后在服务器安装 Node_modules

3.5.2 PM2绑定进程

PM2配置如图所示

3.5.3 配置Nginx
location / {
  proxy_pass  http://127.0.0.1:3000;
}

到此我们的Nest总算发布成功。

MIT License Copyright (c) 2022 杰克 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

nest-admin-api:基于nestjs, typeorm, mysql的api项目 展开 收起
NodeJS 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
NodeJS
1
https://gitee.com/jsfront/nest-admin-api.git
git@gitee.com:jsfront/nest-admin-api.git
jsfront
nest-admin-api
nest-admin-api
master

搜索帮助