Skip to content

Commit aa3998f

Browse files
committed
fix inverse proxy bug
1 parent 7f62e80 commit aa3998f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"name": "anyproxy-package-mock-response",
3-
"version": "1.0.1",
3+
"version": "1.0.3",
44
"description": "mock the response in the way you like",
5-
"main": "index.js",
5+
"main": "rule.js",
66
"anyproxy": {
7-
"rule": "./rule.js",
87
"pluginType": "rule",
98
"menu": {
109
"name": "Mock",

rule.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,19 @@ const handleInverseProxy = (requestDetail, proxyTarget) => {
7070

7171
const excludeSubPath = getSubPathExcludePattern(requestDetail.url, pattern);
7272
const { hostname, port, path: targetPath, protocol } = parseUrl(targetUrl);
73+
const finalPath = handleWinPath(path.join(targetPath, excludeSubPath));
74+
7375
options.hostname = hostname;
7476
requestDetail.protocol = protocol;
7577

7678
if (port) {
7779
options.port = port;
80+
} else {
81+
options.port = protocol === 'https:' ? '443' : '80';
7882
}
7983

80-
const finalPath = handleWinPath(path.join(targetPath, excludeSubPath));
81-
8284
options.path = finalPath;
85+
options.headers.host = hostname + ':' + options.port;
8386
};
8487

8588
module.exports = {

0 commit comments

Comments
 (0)