|
@@ -1,7 +1,7 @@
|
|
|
'use strict';
|
|
|
const Controller = require('egg').Controller;
|
|
|
const { CrudController } = require('naf-framework-mongoose/lib/controller');
|
|
|
-
|
|
|
+const dealList = require('../util/deal-list');
|
|
|
// 请求处理
|
|
|
class RequestController extends Controller {
|
|
|
constructor(ctx) {
|
|
@@ -10,13 +10,38 @@ class RequestController extends Controller {
|
|
|
this.httpUtil = this.ctx.service.util.httpUtil;
|
|
|
}
|
|
|
async index() {
|
|
|
- const { url, body, method } = this.util.analyzeUrl();
|
|
|
- // query和url已经合并,没有query了,所以直接body,get方法第二个位置不需要了,也不会传值来(传来就是找茬)
|
|
|
- // create,post,delete都有可能传,而且第二个位置都是body
|
|
|
- const res = await this.httpUtil[`$${method}`](url, body);
|
|
|
- // TODO,此处应该设置再处理名单,若在名单中,则继续处理数据,否则透传
|
|
|
- this.ctx.body = res;
|
|
|
- // this.ctx.ok();
|
|
|
+ const r = this.checkList();
|
|
|
+ if (r) {
|
|
|
+ // 纯人工处理
|
|
|
+ const { service, method } = r;
|
|
|
+ const res = await this.ctx.service[service][method]();
|
|
|
+ this.ctx.body = res;
|
|
|
+ } else {
|
|
|
+ const { url, body, method } = this.util.analyzeUrl();
|
|
|
+ // query和url已经合并,没有query了,所以直接body,get方法第二个位置不需要了,也不会传值来(传来就是找茬)
|
|
|
+ // create,post,delete都有可能传,而且第二个位置都是body
|
|
|
+ const res = await this.httpUtil[`$${method}`](url, body);
|
|
|
+ // TODO,此处应该设置再处理名单,若在名单中,则继续处理数据,否则透传
|
|
|
+ this.ctx.body = res;
|
|
|
+ // this.ctx.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否是纯人工处理路由
|
|
|
+ */
|
|
|
+ checkList() {
|
|
|
+ const { url } = this.ctx.request;
|
|
|
+ let obj;
|
|
|
+ for (const i of dealList) {
|
|
|
+ const { uri, service, method } = i;
|
|
|
+ if (url.includes(uri)) {
|
|
|
+ obj = { service, method };
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
}
|
|
|
}
|
|
|
module.exports = CrudController(RequestController, {});
|