configuration.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Configuration, App, Inject } from '@midwayjs/core';
  2. import * as koa from '@midwayjs/koa';
  3. import * as validate from '@midwayjs/validate';
  4. import * as info from '@midwayjs/info';
  5. import * as swagger from '@midwayjs/swagger';
  6. import * as jwt from '@midwayjs/jwt';
  7. import * as redis from '@midwayjs/redis';
  8. import * as axios from '@midwayjs/axios';
  9. // import { IMidwayContainer } from '@midwayjs/core';
  10. import { join } from 'path';
  11. // freemidway组件项目
  12. import * as FreeFrame from 'free-midway-component';
  13. // import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
  14. // 控制器执行前函数
  15. import { CheckTokenMiddleware } from './middleware/checkToken.middleware';
  16. // 请求成功,失败提示
  17. // const axiosResponse = response => {
  18. // if (response.status === 0) return response.data;
  19. // else {
  20. // console.log(JSON.stringify(response));
  21. // throw new ServiceError('请求失败', FrameworkErrorEnum.SERVICE_FAULT);
  22. // }
  23. // };
  24. // const axiosError = error => {
  25. // return Promise.reject(error);
  26. // };
  27. @Configuration({
  28. imports: [
  29. FreeFrame,
  30. validate,
  31. jwt,
  32. redis,
  33. axios,
  34. swagger,
  35. {
  36. component: info,
  37. enabledEnvironment: ['local'],
  38. },
  39. ],
  40. importConfigs: [join(__dirname, './config')],
  41. })
  42. export class ContainerLifeCycle {
  43. @App()
  44. app: koa.Application;
  45. @Inject()
  46. bullFramework: bull.Framework;
  47. async onReady() {
  48. this.app.getMiddleware().insertFirst(CheckTokenMiddleware);
  49. }
  50. }