Skip to content

Commit 1dc9461

Browse files
koba04SpaceK33z
authored andcommitted
Fix to share proxy option between proxy settings when the proxy option is a same object (#836)
1 parent 42cd23c commit 1dc9461

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/Server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function Server(compiler, options) {
159159
target: options.proxy[context]
160160
};
161161
} else {
162-
proxyOptions = options.proxy[context];
162+
proxyOptions = Object.assign({}, options.proxy[context]);
163163
proxyOptions.context = correctedContext;
164164
}
165165
proxyOptions.logLevel = proxyOptions.logLevel || "warn";

test/Proxy.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,44 @@ describe("Proxy", function() {
144144
.expect(200, "from proxy2", done);
145145
});
146146
});
147+
148+
context("sharing a proxy option", function() {
149+
let server;
150+
let req;
151+
let listener;
152+
const proxyTarget = {
153+
target: "http://localhost:9000"
154+
};
155+
156+
before(function(done) {
157+
const proxy = express();
158+
proxy.get("*", function(req, res) {
159+
res.send("from proxy");
160+
});
161+
listener = proxy.listen(9000);
162+
server = helper.start(config, {
163+
contentBase,
164+
proxy: {
165+
"/proxy1": proxyTarget,
166+
"/proxy2": proxyTarget,
167+
}
168+
}, done);
169+
req = request(server.app);
170+
});
171+
172+
after(function(done) {
173+
helper.close(function() {
174+
listener.close();
175+
done();
176+
});
177+
});
178+
179+
it("respects proxy1 option", function(done) {
180+
req.get("/proxy1").expect(200, "from proxy", done);
181+
});
182+
183+
it("respects proxy2 option", function(done) {
184+
req.get("/proxy2").expect(200, "from proxy", done);
185+
});
186+
});
147187
});

0 commit comments

Comments
 (0)