diff --git a/server/httpproxy/controllers/proxy.js b/server/httpproxy/controllers/proxy.js index 7789fe2..c7c2138 100644 --- a/server/httpproxy/controllers/proxy.js +++ b/server/httpproxy/controllers/proxy.js @@ -4,7 +4,7 @@ const utils = require('j7/utils'); const http = require('j7/http'); const serviceFactory = require('../services/factory'); -async function get(session) { +async function internalGet(session) { const seqId = session.request('seq_id'); const targetUrl = session.request('target_url'); const cbUrl = session.request('cb_url'); @@ -28,6 +28,43 @@ async function get(session) { await http.get(cbUrl, rspJson); }); session.rspOk(); +} + +async function internalPost(session, postData) { + const seqId = session.request('seq_id'); + const targetUrl = session.request('target_url'); + const cbUrl = session.request('cb_url'); + const reqJson = session.requestToJson(); + new Promise(async (resolve) => { + const params = utils.jsonDecode(session.request('params')); + delete params['__POST']; + const {err, data} = await http.post(targetUrl, params, postData); + const rspJson = { + 'errcode': 0, + 'errmsg': '', + 'seq_id': seqId, + 'req_json': reqJson, + 'data': data + }; + if (err) { + rspJson['errcode'] = 1; + rspJson['errmsg'] = '' + err; + } + console.log('data', data); + console.log('rspJson:' + utils.jsonEncode(rspJson)); + await http.get(cbUrl, rspJson); + }); + session.rspOk(); +} + +async function get(session) { + const params = utils.jsonDecode(session.request('params')); + const postData = utils.getVal(params, '__POST', ''); + if (postData) { + await internalPost(session, postData); + } else { + await internalGet(session); + } }; async function post(session) { diff --git a/third_party/j7 b/third_party/j7 index 59b3ef2..f81baf8 160000 --- a/third_party/j7 +++ b/third_party/j7 @@ -1 +1 @@ -Subproject commit 59b3ef222d3468ccb7096a801a43da7d9b158412 +Subproject commit f81baf8c264c00395b4dd27f900df6ffedceac08