Skip to content

Commit

Permalink
fix: multi compiler mode with proxy (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 3, 2020
1 parent 7f2275f commit 247a92b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Server.js
Expand Up @@ -200,8 +200,12 @@ class Server {
return level;
};

const configs = getCompilerConfigArray(this.compiler);
const configWithDevServer =
configs.find((config) => config.devServer) || configs[0];

proxyOptions.logLevel = getLogLevelForProxy(
this.compiler.options.infrastructureLogging.level
configWithDevServer.infrastructureLogging.level
);
proxyOptions.logProvider = () => this.logger;

Expand Down
38 changes: 38 additions & 0 deletions test/server/proxy-option.test.js
Expand Up @@ -474,4 +474,42 @@ describe('proxy option', () => {
req.delete('/delete').expect(200, 'DELETE method from proxy', done);
});
});

describe('should work in multi compiler mode', () => {
let server;
let req;
let closeProxyServers;

beforeAll((done) => {
closeProxyServers = startProxyServers();
server = testServer.start(
[config, config],
{
static: {
directory: contentBase,
watch: false,
},
proxy: {
'*': {
context: () => true,
target: `http://localhost:${port1}`,
},
},
port: port3,
},
done
);
req = request(server.app);
});

afterAll((done) => {
testServer.close(() => {
closeProxyServers(done);
});
});

it('respects a proxy option', (done) => {
req.get('/proxy1').expect(200, 'from proxy1', done);
});
});
});

0 comments on commit 247a92b

Please sign in to comment.