zs 1 vuosi sitten
vanhempi
commit
84e823aa34

+ 20 - 0
ecosystem.config.js

@@ -0,0 +1,20 @@
+'use strict';
+// 开发服务设置
+const app = '耗材vue3-服务';
+module.exports = {
+  apps: [
+    {
+      name: app, // 应用名称
+      script: './bootstrap.js', // 实际启动脚本
+      out: `./logs/${app}.log`,
+      error: `./logs/${app}.err`,
+      watch: [
+        // 监控变化的目录,一旦变化,自动重启
+        'dist',
+      ],
+      env: {
+        NODE_ENV: 'production', // 环境参数,当前指定为生产环境
+      },
+    },
+  ],
+};

+ 20 - 1
package.json

@@ -4,19 +4,38 @@
   "description": "",
   "private": true,
   "dependencies": {
+    "@midwayjs/axios": "^3.11.15",
     "@midwayjs/bootstrap": "^3.0.0",
     "@midwayjs/core": "^3.0.0",
     "@midwayjs/decorator": "^3.0.0",
     "@midwayjs/info": "^3.0.0",
+    "@midwayjs/jwt": "^3.11.15",
     "@midwayjs/koa": "^3.0.0",
     "@midwayjs/logger": "^2.14.0",
-    "@midwayjs/validate": "^3.0.0"
+    "@midwayjs/redis": "^3.11.15",
+    "@midwayjs/swagger": "^3.11.15",
+    "@midwayjs/task": "^3.6.0",
+    "@midwayjs/typegoose": "^3.11.15",
+    "@midwayjs/validate": "^3.0.0",
+    "@midwayjs/web": "^3.11.15",
+    "@typegoose/typegoose": "^11.4.0",
+    "amqp-connection-manager": "^4.1.13",
+    "amqplib": "^0.10.3",
+    "exceljs": "^4.3.0",
+    "free-midway-component": "^1.0.35",
+    "midway-schedule": "^2.15.0",
+    "moment": "^2.29.4",
+    "mongoose": "^7.4.1",
+    "swagger-ui-dist": "^5.2.0"
   },
   "devDependencies": {
     "@midwayjs/cli": "^2.0.0",
     "@midwayjs/mock": "^3.0.0",
+    "@types/amqplib": "^0.10.1",
     "@types/jest": "^29.2.0",
+    "@types/jsonwebtoken": "^9.0.2",
     "@types/koa": "^2.13.4",
+    "@types/lodash": "^4.14.196",
     "@types/node": "14",
     "cross-env": "^6.0.0",
     "jest": "^29.2.2",

+ 34 - 2
src/config/config.default.ts

@@ -1,9 +1,41 @@
 import { MidwayConfig } from '@midwayjs/core';
 
+const project = 'material';
 export default {
   // use for cookie sign key, should change to your own and keep security
-  keys: '1690358370175_5493',
+  keys: '1672292154640_5493',
   koa: {
-    port: 7001,
+    port: 13004,
+  },
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+    expiresIn: '2d',
+  },
+  redis_timeout: 300, //s
+  emailConfig: project,
+  axios: {
+    clients: {
+      Axios: {
+        baseURL: 'http://broadcast.waityou24.cn',
+        //表明返回服务器返回的数据类型
+        responseType: 'arraybuffer',
+        headers: {
+          'Content-Type': 'application/json; application/octet-stream',
+        },
+      },
+    },
+  },
+  export: {
+    root_path: 'D:\\temp',
+    file_type: 'friendSchool',
+  },
+  wechatSetting: {
+    // 吉林大学汽车工程学院校友会
+    friendShoolApp: {
+      appid: 'wxef5b87d5fef241b4',
+      secret: 'd315753502e0cbc24de5a230bed5c87a',
+      mchid: '1505364491',
+      v3key: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9',
+    },
   },
 } as MidwayConfig;

+ 63 - 0
src/config/config.local.ts

@@ -0,0 +1,63 @@
+import { MidwayConfig } from '@midwayjs/core';
+const ip = '127.0.0.1';
+const project = 'material';
+const mongodb = 'material_v1';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1672292154640_5493',
+  koa: {
+    globalPrefix: `/${project}/v1/api`,
+  },
+  swagger: {
+    swaggerPath: `/dev/${project}/v1/api/doc`,
+  },
+  mongoose: {
+    dataSource: {
+      default: {
+        uri: `mongodb://${ip}:27017/${mongodb}`,
+        options: {
+          user: 'admin',
+          pass: 'admin',
+          authSource: 'admin',
+          useNewUrlParser: true,
+        },
+        entities: ['./entity'],
+      },
+    },
+  },
+  bull: {
+    defaultQueueOptions: {
+      redis: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '123456',
+      },
+      prefix: '{midway-bull}',
+    },
+  },
+  axios: {
+    clients: {
+      file: {
+        baseURL: 'http://broadcast.waityou24.cn',
+        //表明返回服务器返回的数据类型
+        responseType: 'arraybuffer',
+        headers: {
+          'Content-Type': 'application/json; application/octet-stream',
+        },
+      },
+    },
+  },
+  export: {
+    root_path: 'D:\\temp',
+    file_type: 'friendSchool',
+  },
+  wechatSetting: {
+    // 吉林大学汽车工程学院校友会
+    friendShoolApp: {
+      appid: 'wxef5b87d5fef241b4',
+      secret: 'd315753502e0cbc24de5a230bed5c87a',
+      mchid: '1505364491',
+      v3key: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9',
+    },
+  },
+} as MidwayConfig;

+ 63 - 0
src/config/config.prod.ts

@@ -0,0 +1,63 @@
+import { MidwayConfig } from '@midwayjs/core';
+const ip = '127.0.0.1';
+const project = 'material';
+const mongodb = 'material_v1';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1672292154640_5493',
+  koa: {
+    globalPrefix: `/${project}/v1/api`,
+  },
+  swagger: {
+    swaggerPath: `/${project}/v1/api/doc`,
+  },
+  mongoose: {
+    dataSource: {
+      default: {
+        uri: `mongodb://${ip}:27017/${mongodb}`,
+        options: {
+          user: 'admin',
+          pass: 'admin',
+          authSource: 'admin',
+          useNewUrlParser: true,
+        },
+        entities: ['./entity'],
+      },
+    },
+  },
+  bull: {
+    defaultQueueOptions: {
+      redis: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '123456',
+      },
+      prefix: '{midway-bull}',
+    },
+  },
+  axios: {
+    clients: {
+      file: {
+        baseURL: 'http://broadcast.waityou24.cn',
+        //表明返回服务器返回的数据类型
+        responseType: 'arraybuffer',
+        headers: {
+          'Content-Type': 'application/json; application/octet-stream',
+        },
+      },
+    },
+  },
+  export: {
+    root_path: 'D:\\free\\workspace\\server\\service-file\\upload',
+    file_type: 'friendSchool',
+  },
+  wechatSetting: {
+    // 吉林大学汽车工程学院校友会
+    friendShoolApp: {
+      appid: 'wxef5b87d5fef241b4',
+      secret: 'd315753502e0cbc24de5a230bed5c87a',
+      mchid: '1505364491',
+      v3key: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9',
+    },
+  },
+} as MidwayConfig;

+ 31 - 10
src/configuration.ts

@@ -1,16 +1,37 @@
-import { Configuration, App } from '@midwayjs/core';
+import { Configuration, App, Inject } from '@midwayjs/core';
 import * as koa from '@midwayjs/koa';
 import * as validate from '@midwayjs/validate';
 import * as info from '@midwayjs/info';
+import * as swagger from '@midwayjs/swagger';
+import * as jwt from '@midwayjs/jwt';
+import * as redis from '@midwayjs/redis';
+import * as axios from '@midwayjs/axios';
+// import { IMidwayContainer } from '@midwayjs/core';
 import { join } from 'path';
-// import { DefaultErrorFilter } from './filter/default.filter';
-// import { NotFoundFilter } from './filter/notfound.filter';
-import { ReportMiddleware } from './middleware/report.middleware';
-
+// freemidway组件项目
+import * as FreeFrame from 'free-midway-component';
+// import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+// 控制器执行前函数
+import { CheckTokenMiddleware } from './middleware/checkToken.middleware';
+// 请求成功,失败提示
+// const axiosResponse = response => {
+//   if (response.status === 0) return response.data;
+//   else {
+//     console.log(JSON.stringify(response));
+//     throw new ServiceError('请求失败', FrameworkErrorEnum.SERVICE_FAULT);
+//   }
+// };
+// const axiosError = error => {
+//   return Promise.reject(error);
+// };
 @Configuration({
   imports: [
-    koa,
+    FreeFrame,
     validate,
+    jwt,
+    redis,
+    axios,
+    swagger,
     {
       component: info,
       enabledEnvironment: ['local'],
@@ -22,10 +43,10 @@ export class ContainerLifeCycle {
   @App()
   app: koa.Application;
 
+  @Inject()
+  bullFramework: bull.Framework;
+
   async onReady() {
-    // add middleware
-    this.app.useMiddleware([ReportMiddleware]);
-    // add filter
-    // this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
+    this.app.getMiddleware().insertFirst(CheckTokenMiddleware);
   }
 }

+ 33 - 0
src/middleware/checkToken.middleware.ts

@@ -0,0 +1,33 @@
+import { IMiddleware } from '@midwayjs/core';
+import { Middleware, Inject } from '@midwayjs/decorator';
+import { NextFunction, Context } from '@midwayjs/koa';
+import get = require('lodash/get');
+import { JwtService } from '@midwayjs/jwt';
+
+@Middleware()
+export class CheckTokenMiddleware
+  implements IMiddleware<Context, NextFunction>
+{
+  @Inject()
+  jwtService: JwtService;
+  resolve() {
+    return async (ctx: Context, next: NextFunction) => {
+      const token: any = get(ctx.request, 'header.token');
+      if (token) {
+        const data = this.jwtService.decodeSync(token);
+        if (data) ctx.user = data;
+      }
+      // 添加管理员身份
+      const adminToken: any = get(ctx.request, 'header.admin-token');
+      if (adminToken) {
+        const data = this.jwtService.decodeSync(adminToken);
+        if (data) ctx.admin = data;
+      }
+      await next();
+    };
+  }
+
+  static getName(): string {
+    return 'checkToken';
+  }
+}