From f49e2f0445d894332006db1760efd733450126bc Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Mon, 13 Aug 2018 07:27:40 +0800 Subject: [PATCH] fix: proxy file uploading (#786) fix #713 fix #669 fix https://github.com/ant-design/ant-design-pro/issues/417 fix https://github.com/ant-design/ant-design-pro/issues/1510 fix https://github.com/ant-design/ant-design-pro/issues/892 --- package.json | 2 +- src/utils/mock.js | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 1b7b7eb..e5e5585 100644 --- a/package.json +++ b/package.json @@ -49,9 +49,9 @@ "chalk": "^1.1.3", "chokidar": "^1.7.0", "debug": "^3.1.0", - "express-http-proxy": "^0.11.0", "glob": "^7.1.2", "graceful-process": "^1.1.0", + "http-proxy-middleware": "^0.18.0", "is-plain-object": "^2.0.3", "lodash.escaperegexp": "^4.1.2", "parse-json-pretty": "^0.1.0", diff --git a/src/utils/mock.js b/src/utils/mock.js index e7fe4e3..583ccda 100644 --- a/src/utils/mock.js +++ b/src/utils/mock.js @@ -2,7 +2,7 @@ import { existsSync } from 'fs'; import assert from 'assert'; import chokidar from 'chokidar'; import chalk from 'chalk'; -import proxy from 'express-http-proxy'; +import proxy from 'http-proxy-middleware'; import url from 'url'; import { join } from 'path'; import bodyParser from 'body-parser'; @@ -43,19 +43,18 @@ function createMockHandler(method, path, value) { } function createProxy(method, path, target) { - return proxy(target, { - filter(req) { - return method ? req.method.toLowerCase() === method.toLowerCase() : true; - }, - forwardPath(req) { - let matchPath = req.originalUrl; - const matches = matchPath.match(path); - if (matches.length > 1) { - matchPath = matches[1]; - } - return winPath(join(url.parse(target).path, matchPath)); - }, - }); + const filter = req => { + return method ? req.method.toLowerCase() === method.toLowerCase() : true; + }; + const router = req => { + let matchPath = req.originalUrl; + const matches = matchPath.match(path); + if (matches.length > 1) { + matchPath = matches[1]; + } + return winPath(join(url.parse(target).path, matchPath)); + }; + return proxy(filter, { router }); } export function applyMock(devServer) {