Skip to content

Commit 247a92b

Browse files
fix: multi compiler mode with proxy (#2905)
1 parent 7f2275f commit 247a92b

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/Server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ class Server {
200200
return level;
201201
};
202202

203+
const configs = getCompilerConfigArray(this.compiler);
204+
const configWithDevServer =
205+
configs.find((config) => config.devServer) || configs[0];
206+
203207
proxyOptions.logLevel = getLogLevelForProxy(
204-
this.compiler.options.infrastructureLogging.level
208+
configWithDevServer.infrastructureLogging.level
205209
);
206210
proxyOptions.logProvider = () => this.logger;
207211

test/server/proxy-option.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,42 @@ describe('proxy option', () => {
474474
req.delete('/delete').expect(200, 'DELETE method from proxy', done);
475475
});
476476
});
477+
478+
describe('should work in multi compiler mode', () => {
479+
let server;
480+
let req;
481+
let closeProxyServers;
482+
483+
beforeAll((done) => {
484+
closeProxyServers = startProxyServers();
485+
server = testServer.start(
486+
[config, config],
487+
{
488+
static: {
489+
directory: contentBase,
490+
watch: false,
491+
},
492+
proxy: {
493+
'*': {
494+
context: () => true,
495+
target: `http://localhost:${port1}`,
496+
},
497+
},
498+
port: port3,
499+
},
500+
done
501+
);
502+
req = request(server.app);
503+
});
504+
505+
afterAll((done) => {
506+
testServer.close(() => {
507+
closeProxyServers(done);
508+
});
509+
});
510+
511+
it('respects a proxy option', (done) => {
512+
req.get('/proxy1').expect(200, 'from proxy1', done);
513+
});
514+
});
477515
});

0 commit comments

Comments
 (0)