Skip to content

Commit

Permalink
fix: proxy file uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Aug 11, 2018
1 parent e3ff293 commit 256ec4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -49,7 +49,6 @@
"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",
"is-plain-object": "^2.0.3",
Expand Down
27 changes: 13 additions & 14 deletions src/utils/mock.js
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 256ec4f

Please sign in to comment.