diff --git a/server/package.json b/server/package.json index 60d813b..39e4b04 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "mockm", - "version": "1.1.26-alpha.26", + "version": "1.1.26-alpha.27", "description": "Analog interface server, painless parallel development of front and back ends.", "main": "server.js", "bin": { diff --git a/server/util/business.js b/server/util/business.js index bccf20c..f564881 100644 --- a/server/util/business.js +++ b/server/util/business.js @@ -1878,6 +1878,9 @@ function business() { // 与业务相关性的函数 // // } // }) reqHandle().injectionReq({req, res, type: `get`}) + + // https://github.com/chimurai/http-proxy-middleware/pull/492 + require(`http-proxy-middleware`).fixRequestBody(proxyReq, req) }, onProxyRes: (proxyRes, req, res) => { allowCors({res: proxyRes, req, proxyConfig: userConfig}) diff --git a/test/config.proxy.test.js b/test/config.proxy.test.js index b3bac3d..4462eb4 100644 --- a/test/config.proxy.test.js +++ b/test/config.proxy.test.js @@ -2,6 +2,29 @@ const util = require('./util.js') const http = util.http describe('config.proxy', () => { + it(`代理到原始服务器`, async () => { + util.ok(await util.runMockm({ + mockm: () => ({ + proxy: { + '/': `http://www.httpbin.org`, + }, + }), + okFn: async ({arg, str}) => { + const get = (await http.get(`http://127.0.0.1:${arg.port}/get?a=1&b=2`)).data + const post = (await http.post(`http://127.0.0.1:${arg.port}/post`, {a: 1, b: 2})).data + const bin = (await http.get(`http://127.0.0.1:${arg.port}/image/png`)).data + const form = (await util.upload(`http://127.0.0.1:${arg.port}/post`, {a: 1, b: 2})).data + const upload = (await util.upload(`http://127.0.0.1:${arg.port}/post`, {f1: require(`fs`).createReadStream(__filename)})).data + return ( + get.args.a === `1` + && post.json.a === 1 + && bin.match(`PNG`) + && form.form.a === `1` + && util.getType(upload.files.f1, `string`) + ) + }, + })) + }) it(`拦截请求`, async () => { util.ok(await util.runMockm({ mockm: () => ({ diff --git a/test/util.js b/test/util.js index 9cc9c4d..ef6a4e2 100644 --- a/test/util.js +++ b/test/util.js @@ -462,6 +462,7 @@ function upload(api, data) { } module.exports = { + getType, upload, to, ok,