Skip to content

Commit

Permalink
fix: proxy file uploading (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck authored and sorrycc committed Aug 12, 2018
1 parent 4a05bcb commit f49e2f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 13 additions & 14 deletions src/utils/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f49e2f0

Please sign in to comment.