0.0.2 • Published 4 years ago

@cyyjs/nestjs v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

nestjs 封装库

封装内容

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

安装

yarn add @cyyjs/nestjs

使用

// main.ts

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

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/nestjs/auth'
@Module({
  imports: [
    AuthModule.register({
      url: '' // 获取用户信息的url
    })
  ],
  controllers: [AppController],
  providers: [
    {
      provide: APP_GUARD,
      useClass: RolesGuard
    },
    AppService
  ],
})
export class AppModule {}
0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago