Skip to content

Commit

Permalink
Fix to share proxy option between proxy settings when the proxy optio…
Browse files Browse the repository at this point in the history
…n is a same object (#836)
  • Loading branch information
koba04 authored and SpaceK33z committed Mar 9, 2017
1 parent 42cd23c commit 1dc9461
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function Server(compiler, options) {
target: options.proxy[context]
};
} else {
proxyOptions = options.proxy[context];
proxyOptions = Object.assign({}, options.proxy[context]);
proxyOptions.context = correctedContext;
}
proxyOptions.logLevel = proxyOptions.logLevel || "warn";
Expand Down
40 changes: 40 additions & 0 deletions test/Proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,44 @@ describe("Proxy", function() {
.expect(200, "from proxy2", done);
});
});

context("sharing a proxy option", function() {
let server;
let req;
let listener;
const proxyTarget = {
target: "http://localhost:9000"
};

before(function(done) {
const proxy = express();
proxy.get("*", function(req, res) {
res.send("from proxy");
});
listener = proxy.listen(9000);
server = helper.start(config, {
contentBase,
proxy: {
"/proxy1": proxyTarget,
"/proxy2": proxyTarget,
}
}, done);
req = request(server.app);
});

after(function(done) {
helper.close(function() {
listener.close();
done();
});
});

it("respects proxy1 option", function(done) {
req.get("/proxy1").expect(200, "from proxy", done);
});

it("respects proxy2 option", function(done) {
req.get("/proxy2").expect(200, "from proxy", done);
});
});
});

0 comments on commit 1dc9461

Please sign in to comment.