Skip to content

Commit 986a76a

Browse files
Merge branch 'master' into update-ws
2 parents 17d6760 + 2adfd01 commit 986a76a

5 files changed

+317
-35
lines changed

lib/Server.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,12 @@ class Server {
492492
* }
493493
*/
494494
if (typeof options.proxy !== "undefined") {
495+
// TODO remove in the next major release, only accept `Array`
495496
if (!Array.isArray(options.proxy)) {
496-
if (Object.prototype.hasOwnProperty.call(options.proxy, "target")) {
497+
if (
498+
Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
499+
Object.prototype.hasOwnProperty.call(options.proxy, "router")
500+
) {
497501
options.proxy = [options.proxy];
498502
} else {
499503
options.proxy = Object.keys(options.proxy).map((context) => {
@@ -513,38 +517,42 @@ class Server {
513517
proxyOptions.context = correctedContext;
514518
}
515519

516-
const getLogLevelForProxy = (level) => {
517-
if (level === "none") {
518-
return "silent";
519-
}
520+
return proxyOptions;
521+
});
522+
}
523+
}
520524

521-
if (level === "log") {
522-
return "info";
523-
}
525+
options.proxy = options.proxy.map((item) => {
526+
const getLogLevelForProxy = (level) => {
527+
if (level === "none") {
528+
return "silent";
529+
}
524530

525-
if (level === "verbose") {
526-
return "debug";
527-
}
531+
if (level === "log") {
532+
return "info";
533+
}
528534

529-
return level;
530-
};
535+
if (level === "verbose") {
536+
return "debug";
537+
}
531538

532-
if (typeof proxyOptions.logLevel === "undefined") {
533-
proxyOptions.logLevel = getLogLevelForProxy(
534-
compilerOptions.infrastructureLogging
535-
? compilerOptions.infrastructureLogging.level
536-
: "info"
537-
);
538-
}
539+
return level;
540+
};
539541

540-
if (typeof proxyOptions.logProvider === "undefined") {
541-
proxyOptions.logProvider = () => this.logger;
542-
}
542+
if (typeof item.logLevel === "undefined") {
543+
item.logLevel = getLogLevelForProxy(
544+
compilerOptions.infrastructureLogging
545+
? compilerOptions.infrastructureLogging.level
546+
: "info"
547+
);
548+
}
543549

544-
return proxyOptions;
545-
});
550+
if (typeof item.logProvider === "undefined") {
551+
item.logProvider = () => this.logger;
546552
}
547-
}
553+
554+
return item;
555+
});
548556
}
549557

550558
if (typeof options.setupExitSignals === "undefined") {
@@ -875,22 +883,24 @@ class Server {
875883

876884
// It is possible to use the `bypass` method without a `target`.
877885
// However, the proxy middleware has no use in this case, and will fail to instantiate.
878-
if (proxyConfig.target) {
886+
if (context) {
879887
return createProxyMiddleware(context, proxyConfig);
880888
}
889+
890+
return createProxyMiddleware(proxyConfig);
881891
};
882892
/**
883893
* Assume a proxy configuration specified as:
884894
* proxy: [
885895
* {
886-
* context: ...,
887-
* ...options...
896+
* context: "value",
897+
* ...options,
888898
* },
889899
* // or:
890900
* function() {
891901
* return {
892-
* context: ...,
893-
* ...options...
902+
* context: "context",
903+
* ...options,
894904
* };
895905
* }
896906
* ]
@@ -903,7 +913,9 @@ class Server {
903913
? proxyConfigOrCallback()
904914
: proxyConfigOrCallback;
905915

906-
proxyMiddleware = getProxyMiddleware(proxyConfig);
916+
if (!proxyConfig.bypass) {
917+
proxyMiddleware = getProxyMiddleware(proxyConfig);
918+
}
907919

908920
if (proxyConfig.ws) {
909921
this.webSocketProxies.push(proxyMiddleware);
@@ -922,6 +934,7 @@ class Server {
922934
// - Check if we have a bypass function defined
923935
// - In case the bypass function is defined we'll retrieve the
924936
// bypassUrl from it otherwise bypassUrl would be null
937+
// TODO remove in the next major in favor `context` and `router` options
925938
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
926939
const bypassUrl = isByPassFuncDefined
927940
? await proxyConfig.bypass(req, res, proxyConfig)

test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack4

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ Array [
2424

2525
exports[`web socket communication should work and close web socket client connection when web socket server closed ("ws"): page errors 1`] = `Array []`;
2626

27+
exports[`web socket communication should work and reconnect when the connection is lost ("sockjs"): console messages 1`] = `
28+
Array [
29+
"[HMR] Waiting for update signal from WDS...",
30+
"Hey.",
31+
"[webpack-dev-server] Hot Module Replacement enabled.",
32+
"[webpack-dev-server] Live Reloading enabled.",
33+
"[webpack-dev-server] Disconnected!",
34+
"[webpack-dev-server] Hot Module Replacement enabled.",
35+
"[webpack-dev-server] Live Reloading enabled.",
36+
"[webpack-dev-server] App hot update...",
37+
"[HMR] Checking for updates on the server...",
38+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
39+
"[HMR] Cannot find update. Need to do a full reload!",
40+
"[HMR] (Probably because of restarting the webpack-dev-server)",
41+
"[HMR] Waiting for update signal from WDS...",
42+
"Hey.",
43+
"[webpack-dev-server] Hot Module Replacement enabled.",
44+
"[webpack-dev-server] Live Reloading enabled.",
45+
]
46+
`;
47+
48+
exports[`web socket communication should work and reconnect when the connection is lost ("sockjs"): page errors 1`] = `Array []`;
49+
50+
exports[`web socket communication should work and reconnect when the connection is lost ("ws"): console messages 1`] = `
51+
Array [
52+
"[HMR] Waiting for update signal from WDS...",
53+
"Hey.",
54+
"[webpack-dev-server] Hot Module Replacement enabled.",
55+
"[webpack-dev-server] Live Reloading enabled.",
56+
"[webpack-dev-server] Disconnected!",
57+
"[webpack-dev-server] Hot Module Replacement enabled.",
58+
"[webpack-dev-server] Live Reloading enabled.",
59+
"[webpack-dev-server] App hot update...",
60+
"[HMR] Checking for updates on the server...",
61+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
62+
"[HMR] Cannot find update. Need to do a full reload!",
63+
"[HMR] (Probably because of restarting the webpack-dev-server)",
64+
"[HMR] Waiting for update signal from WDS...",
65+
"Hey.",
66+
"[webpack-dev-server] Hot Module Replacement enabled.",
67+
"[webpack-dev-server] Live Reloading enabled.",
68+
]
69+
`;
70+
71+
exports[`web socket communication should work and reconnect when the connection is lost ("ws"): page errors 1`] = `Array []`;
72+
2773
exports[`web socket communication should work and terminate client that is not alive ("sockjs"): console messages 1`] = `
2874
Array [
2975
"[HMR] Waiting for update signal from WDS...",

test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack5

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ Array [
2424

2525
exports[`web socket communication should work and close web socket client connection when web socket server closed ("ws"): page errors 1`] = `Array []`;
2626

27+
exports[`web socket communication should work and reconnect when the connection is lost ("sockjs"): console messages 1`] = `
28+
Array [
29+
"[HMR] Waiting for update signal from WDS...",
30+
"Hey.",
31+
"[webpack-dev-server] Hot Module Replacement enabled.",
32+
"[webpack-dev-server] Live Reloading enabled.",
33+
"[webpack-dev-server] Disconnected!",
34+
"[webpack-dev-server] Hot Module Replacement enabled.",
35+
"[webpack-dev-server] Live Reloading enabled.",
36+
"[webpack-dev-server] App hot update...",
37+
"[HMR] Checking for updates on the server...",
38+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
39+
"[HMR] Cannot find update. Need to do a full reload!",
40+
"[HMR] (Probably because of restarting the webpack-dev-server)",
41+
"[HMR] Waiting for update signal from WDS...",
42+
"Hey.",
43+
"[webpack-dev-server] Hot Module Replacement enabled.",
44+
"[webpack-dev-server] Live Reloading enabled.",
45+
]
46+
`;
47+
48+
exports[`web socket communication should work and reconnect when the connection is lost ("sockjs"): page errors 1`] = `Array []`;
49+
50+
exports[`web socket communication should work and reconnect when the connection is lost ("ws"): console messages 1`] = `
51+
Array [
52+
"[HMR] Waiting for update signal from WDS...",
53+
"Hey.",
54+
"[webpack-dev-server] Hot Module Replacement enabled.",
55+
"[webpack-dev-server] Live Reloading enabled.",
56+
"[webpack-dev-server] Disconnected!",
57+
"[webpack-dev-server] Hot Module Replacement enabled.",
58+
"[webpack-dev-server] Live Reloading enabled.",
59+
"[webpack-dev-server] App hot update...",
60+
"[HMR] Checking for updates on the server...",
61+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
62+
"[HMR] Cannot find update. Need to do a full reload!",
63+
"[HMR] (Probably because of restarting the webpack-dev-server)",
64+
"[HMR] Waiting for update signal from WDS...",
65+
"Hey.",
66+
"[webpack-dev-server] Hot Module Replacement enabled.",
67+
"[webpack-dev-server] Live Reloading enabled.",
68+
]
69+
`;
70+
71+
exports[`web socket communication should work and reconnect when the connection is lost ("ws"): page errors 1`] = `Array []`;
72+
2773
exports[`web socket communication should work and terminate client that is not alive ("sockjs"): console messages 1`] = `
2874
Array [
2975
"[HMR] Waiting for update signal from WDS...",

test/e2e/web-socket-communication.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ describe("web socket communication", () => {
109109
await server.stop();
110110
});
111111

112-
// TODO uncomment after fix regression in webpack
113-
it.skip(`should work and reconnect when the connection is lost ("${websocketServer}")`, async () => {
112+
it(`should work and reconnect when the connection is lost ("${websocketServer}")`, async () => {
114113
WebsocketServer.heartbeatInterval = 100;
115114

116115
const compiler = webpack(config);

0 commit comments

Comments
 (0)