1.0.0-rc2 • Published 3 years ago

@cyyjs/nest v1.0.0-rc2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

nestjs 封装库

封装内容

  • 异常过滤器
  • 返回拦截器、超时拦截器
  • swagger文档
  • 全局验证管道
  • auth授权

安装

yarn add @cyyjs/nest

使用

// main.ts

import { AppModule } from './app.module';
import { CNestFactory } from '@cyyjs/nest/core'

async function bootstrap() {
  const app = await CNestFactory.create(AppModule, {
    applicationOptions: {}, // NestApplicationOptions
    validationPipeOptions: {}, // ValidationPipeOptions
    swaggerOptions: {
      path: '/swagger',
      title: 'API'
      description: 'API'
      version: '1.0.0'
    },
    filters: {
      exception: true
    },
    interceptors: {
      result: true,
      timeout: {
        time: 5000
      }
    }
  });
  await app.listen(3000);
  console.log(`app start at http://localhost:${3000}`)
}
bootstrap();

CNestFactory.create的默认配置:

{
  "filters": {
    "exception": true
  },
  "interceptors": {
    "result": true,
    "timeout": {
      "time": 5000
    }
  }
}

auth

使用 jwt授权

import { AuthModule, RolesGuard } from '@cyyjs/nest/auth'
@Module({
  imports: [
    AuthModule.register({
      url: '' // 获取用户信息的url
    })
  ],
  controllers: [AppController],
  providers: [
    {
      provide: APP_GUARD,
      useClass: RolesGuard
    },
    AppService
  ],
})
export class AppModule {}