webpack-dev-server 4.7.3 → 4.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli-flags.js +26 -22
- package/lib/Server.js +124 -127
- package/lib/options.json +59 -12
- package/package.json +13 -12
- package/types/bin/cli-flags.d.ts +29 -21
- package/types/lib/Server.d.ts +503 -303
package/bin/cli-flags.js
CHANGED
|
@@ -46,13 +46,13 @@ module.exports = {
|
|
|
46
46
|
multiple: false,
|
|
47
47
|
description:
|
|
48
48
|
"Allows to broadcasts dev server via ZeroConf networking on start.",
|
|
49
|
+
negatedDescription:
|
|
50
|
+
"Disallows to broadcasts dev server via ZeroConf networking on start.",
|
|
49
51
|
path: "bonjour",
|
|
50
52
|
},
|
|
51
53
|
],
|
|
52
54
|
description:
|
|
53
55
|
"Allows to broadcasts dev server via ZeroConf networking on start.",
|
|
54
|
-
negatedDescription:
|
|
55
|
-
"Disallows to broadcasts dev server via ZeroConf networking on start.",
|
|
56
56
|
simpleType: "boolean",
|
|
57
57
|
multiple: false,
|
|
58
58
|
},
|
|
@@ -93,13 +93,13 @@ module.exports = {
|
|
|
93
93
|
multiple: false,
|
|
94
94
|
description:
|
|
95
95
|
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
96
|
+
negatedDescription:
|
|
97
|
+
"Disables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
96
98
|
path: "client.overlay",
|
|
97
99
|
},
|
|
98
100
|
],
|
|
99
101
|
description:
|
|
100
102
|
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
101
|
-
negatedDescription:
|
|
102
|
-
"Disables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
103
103
|
simpleType: "boolean",
|
|
104
104
|
multiple: false,
|
|
105
105
|
},
|
|
@@ -140,12 +140,12 @@ module.exports = {
|
|
|
140
140
|
multiple: false,
|
|
141
141
|
description:
|
|
142
142
|
"Prints compilation progress in percentage in the browser.",
|
|
143
|
+
negatedDescription:
|
|
144
|
+
"Does not print compilation progress in percentage in the browser.",
|
|
143
145
|
path: "client.progress",
|
|
144
146
|
},
|
|
145
147
|
],
|
|
146
148
|
description: "Prints compilation progress in percentage in the browser.",
|
|
147
|
-
negatedDescription:
|
|
148
|
-
"Does not print compilation progress in percentage in the browser.",
|
|
149
149
|
simpleType: "boolean",
|
|
150
150
|
multiple: false,
|
|
151
151
|
},
|
|
@@ -156,6 +156,8 @@ module.exports = {
|
|
|
156
156
|
multiple: false,
|
|
157
157
|
description:
|
|
158
158
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
159
|
+
negatedDescription:
|
|
160
|
+
"Tells dev-server to not to try to connect the client.",
|
|
159
161
|
path: "client.reconnect",
|
|
160
162
|
},
|
|
161
163
|
{
|
|
@@ -163,12 +165,13 @@ module.exports = {
|
|
|
163
165
|
multiple: false,
|
|
164
166
|
description:
|
|
165
167
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
168
|
+
negatedDescription:
|
|
169
|
+
"Tells dev-server to not to try to connect the client.",
|
|
166
170
|
path: "client.reconnect",
|
|
167
171
|
},
|
|
168
172
|
],
|
|
169
173
|
description:
|
|
170
174
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
171
|
-
negatedDescription: "Tells dev-server to not to try to connect the client.",
|
|
172
175
|
simpleType: "string",
|
|
173
176
|
multiple: false,
|
|
174
177
|
},
|
|
@@ -321,11 +324,11 @@ module.exports = {
|
|
|
321
324
|
type: "boolean",
|
|
322
325
|
multiple: false,
|
|
323
326
|
description: "Enables gzip compression for everything served.",
|
|
327
|
+
negatedDescription: "Disables gzip compression for everything served.",
|
|
324
328
|
path: "compress",
|
|
325
329
|
},
|
|
326
330
|
],
|
|
327
331
|
description: "Enables gzip compression for everything served.",
|
|
328
|
-
negatedDescription: "Disables gzip compression for everything served.",
|
|
329
332
|
simpleType: "boolean",
|
|
330
333
|
multiple: false,
|
|
331
334
|
},
|
|
@@ -370,6 +373,7 @@ module.exports = {
|
|
|
370
373
|
type: "boolean",
|
|
371
374
|
multiple: false,
|
|
372
375
|
description: "Enables Hot Module Replacement.",
|
|
376
|
+
negatedDescription: "Disables Hot Module Replacement.",
|
|
373
377
|
path: "hot",
|
|
374
378
|
},
|
|
375
379
|
{
|
|
@@ -377,11 +381,11 @@ module.exports = {
|
|
|
377
381
|
values: ["only"],
|
|
378
382
|
multiple: false,
|
|
379
383
|
description: "Enables Hot Module Replacement.",
|
|
384
|
+
negatedDescription: "Disables Hot Module Replacement.",
|
|
380
385
|
path: "hot",
|
|
381
386
|
},
|
|
382
387
|
],
|
|
383
388
|
description: "Enables Hot Module Replacement.",
|
|
384
|
-
negatedDescription: "Disables Hot Module Replacement.",
|
|
385
389
|
simpleType: "string",
|
|
386
390
|
multiple: false,
|
|
387
391
|
},
|
|
@@ -392,12 +396,12 @@ module.exports = {
|
|
|
392
396
|
multiple: false,
|
|
393
397
|
description:
|
|
394
398
|
"Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option.",
|
|
399
|
+
negatedDescription: "Does not serve over HTTP/2 using SPDY.",
|
|
395
400
|
path: "http2",
|
|
396
401
|
},
|
|
397
402
|
],
|
|
398
403
|
description:
|
|
399
404
|
"Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option.",
|
|
400
|
-
negatedDescription: "Does not serve over HTTP/2 using SPDY.",
|
|
401
405
|
simpleType: "boolean",
|
|
402
406
|
multiple: false,
|
|
403
407
|
},
|
|
@@ -408,13 +412,13 @@ module.exports = {
|
|
|
408
412
|
multiple: false,
|
|
409
413
|
description:
|
|
410
414
|
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option.",
|
|
415
|
+
negatedDescription:
|
|
416
|
+
"Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
411
417
|
path: "https",
|
|
412
418
|
},
|
|
413
419
|
],
|
|
414
420
|
description:
|
|
415
421
|
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option.",
|
|
416
|
-
negatedDescription:
|
|
417
|
-
"Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
418
422
|
simpleType: "boolean",
|
|
419
423
|
multiple: false,
|
|
420
424
|
},
|
|
@@ -620,12 +624,12 @@ module.exports = {
|
|
|
620
624
|
multiple: false,
|
|
621
625
|
description:
|
|
622
626
|
"Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option.",
|
|
627
|
+
negatedDescription: "Does not request for an SSL certificate.",
|
|
623
628
|
path: "https.requestCert",
|
|
624
629
|
},
|
|
625
630
|
],
|
|
626
631
|
description:
|
|
627
632
|
"Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option.",
|
|
628
|
-
negatedDescription: "Does not request for an SSL certificate.",
|
|
629
633
|
simpleType: "boolean",
|
|
630
634
|
multiple: false,
|
|
631
635
|
},
|
|
@@ -656,13 +660,13 @@ module.exports = {
|
|
|
656
660
|
multiple: false,
|
|
657
661
|
description:
|
|
658
662
|
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
663
|
+
negatedDescription:
|
|
664
|
+
"Disables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
659
665
|
path: "liveReload",
|
|
660
666
|
},
|
|
661
667
|
],
|
|
662
668
|
description:
|
|
663
669
|
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
664
|
-
negatedDescription:
|
|
665
|
-
"Disables reload/refresh the page(s) when file changes are detected (enabled by default)",
|
|
666
670
|
simpleType: "boolean",
|
|
667
671
|
multiple: false,
|
|
668
672
|
},
|
|
@@ -673,13 +677,13 @@ module.exports = {
|
|
|
673
677
|
multiple: false,
|
|
674
678
|
description:
|
|
675
679
|
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
680
|
+
negatedDescription:
|
|
681
|
+
"Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
676
682
|
path: "magicHtml",
|
|
677
683
|
},
|
|
678
684
|
],
|
|
679
685
|
description:
|
|
680
686
|
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
681
|
-
negatedDescription:
|
|
682
|
-
"Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
683
687
|
simpleType: "boolean",
|
|
684
688
|
multiple: false,
|
|
685
689
|
},
|
|
@@ -697,12 +701,12 @@ module.exports = {
|
|
|
697
701
|
multiple: false,
|
|
698
702
|
description:
|
|
699
703
|
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
|
|
704
|
+
negatedDescription: "Does not open the default browser.",
|
|
700
705
|
path: "open",
|
|
701
706
|
},
|
|
702
707
|
],
|
|
703
708
|
description:
|
|
704
709
|
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
|
|
705
|
-
negatedDescription: "Does not open the default browser.",
|
|
706
710
|
simpleType: "string",
|
|
707
711
|
multiple: true,
|
|
708
712
|
},
|
|
@@ -786,7 +790,6 @@ module.exports = {
|
|
|
786
790
|
},
|
|
787
791
|
],
|
|
788
792
|
description: "Opens specified page in browser.",
|
|
789
|
-
negatedDescription: "Does not open specified page in browser.",
|
|
790
793
|
simpleType: "string",
|
|
791
794
|
multiple: true,
|
|
792
795
|
},
|
|
@@ -1140,12 +1143,12 @@ module.exports = {
|
|
|
1140
1143
|
multiple: true,
|
|
1141
1144
|
description:
|
|
1142
1145
|
"Tells dev server to use serveIndex middleware when enabled.",
|
|
1146
|
+
negatedDescription:
|
|
1147
|
+
"Does not tell dev server to use serveIndex middleware.",
|
|
1143
1148
|
path: "static[].serveIndex",
|
|
1144
1149
|
},
|
|
1145
1150
|
],
|
|
1146
1151
|
description: "Tells dev server to use serveIndex middleware when enabled.",
|
|
1147
|
-
negatedDescription:
|
|
1148
|
-
"Does not tell dev server to use serveIndex middleware.",
|
|
1149
1152
|
simpleType: "boolean",
|
|
1150
1153
|
multiple: true,
|
|
1151
1154
|
},
|
|
@@ -1155,11 +1158,12 @@ module.exports = {
|
|
|
1155
1158
|
type: "boolean",
|
|
1156
1159
|
multiple: true,
|
|
1157
1160
|
description: "Watches for files in static content directory.",
|
|
1161
|
+
negatedDescription:
|
|
1162
|
+
"Does not watch for files in static content directory.",
|
|
1158
1163
|
path: "static[].watch",
|
|
1159
1164
|
},
|
|
1160
1165
|
],
|
|
1161
1166
|
description: "Watches for files in static content directory.",
|
|
1162
|
-
negatedDescription: "Does not watch for files in static content directory.",
|
|
1163
1167
|
simpleType: "boolean",
|
|
1164
1168
|
multiple: true,
|
|
1165
1169
|
},
|
package/lib/Server.js
CHANGED
|
@@ -25,6 +25,7 @@ const schema = require("./options.json");
|
|
|
25
25
|
/** @typedef {import("express").NextFunction} NextFunction */
|
|
26
26
|
/** @typedef {import("express").RequestHandler} ExpressRequestHandler */
|
|
27
27
|
/** @typedef {import("express").ErrorRequestHandler} ExpressErrorRequestHandler */
|
|
28
|
+
/** @typedef {import("anymatch").Matcher} AnymatchMatcher */
|
|
28
29
|
/** @typedef {import("chokidar").WatchOptions} WatchOptions */
|
|
29
30
|
/** @typedef {import("chokidar").FSWatcher} FSWatcher */
|
|
30
31
|
/** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */
|
|
@@ -64,7 +65,7 @@ const schema = require("./options.json");
|
|
|
64
65
|
/**
|
|
65
66
|
* @typedef {Object} WatchFiles
|
|
66
67
|
* @property {string | string[]} paths
|
|
67
|
-
* @property {WatchOptions & { aggregateTimeout?: number, ignored?:
|
|
68
|
+
* @property {WatchOptions & { aggregateTimeout?: number, ignored?: AnymatchMatcher | string[], poll?: number | boolean }} [options]
|
|
68
69
|
*/
|
|
69
70
|
|
|
70
71
|
/**
|
|
@@ -73,7 +74,7 @@ const schema = require("./options.json");
|
|
|
73
74
|
* @property {string | string[]} [publicPath]
|
|
74
75
|
* @property {boolean | ServeIndexOptions} [serveIndex]
|
|
75
76
|
* @property {ServeStaticOptions} [staticOptions]
|
|
76
|
-
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?:
|
|
77
|
+
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: AnymatchMatcher | string[], poll?: number | boolean }} [watch]
|
|
77
78
|
*/
|
|
78
79
|
|
|
79
80
|
/**
|
|
@@ -110,22 +111,22 @@ const schema = require("./options.json");
|
|
|
110
111
|
*/
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
|
-
* @
|
|
114
|
+
* @callback ByPass
|
|
115
|
+
* @param {Request} req
|
|
116
|
+
* @param {Response} res
|
|
117
|
+
* @param {ProxyConfigArrayItem} proxyConfig
|
|
114
118
|
*/
|
|
115
119
|
|
|
116
120
|
/**
|
|
117
|
-
* @typedef {HttpProxyMiddlewareOptions
|
|
121
|
+
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
|
|
118
122
|
*/
|
|
119
123
|
|
|
120
124
|
/**
|
|
121
|
-
* @
|
|
122
|
-
* @param {Request} req
|
|
123
|
-
* @param {Response} res
|
|
124
|
-
* @param {ProxyConfigArray} proxyConfig
|
|
125
|
+
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
|
|
125
126
|
*/
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
|
-
* @typedef {{
|
|
129
|
+
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
|
|
129
130
|
*/
|
|
130
131
|
|
|
131
132
|
/**
|
|
@@ -194,7 +195,7 @@ const schema = require("./options.json");
|
|
|
194
195
|
* @property {boolean} [http2]
|
|
195
196
|
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
|
|
196
197
|
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
|
|
197
|
-
* @property {ProxyConfigMap |
|
|
198
|
+
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
|
|
198
199
|
* @property {boolean | string | Open | Array<string | Open>} [open]
|
|
199
200
|
* @property {boolean} [setupExitSignals]
|
|
200
201
|
* @property {boolean | ClientConfiguration} [client]
|
|
@@ -754,7 +755,7 @@ class Server {
|
|
|
754
755
|
// TODO remove `{}` after drop webpack v4 support
|
|
755
756
|
const compilerWatchOptions = compilerOptions.watchOptions || {};
|
|
756
757
|
/**
|
|
757
|
-
* @param {WatchOptions &
|
|
758
|
+
* @param {WatchOptions & { aggregateTimeout?: number, ignored?: AnymatchMatcher | string[], poll?: number | boolean }} watchOptions
|
|
758
759
|
* @returns {WatchOptions}
|
|
759
760
|
*/
|
|
760
761
|
const getWatchOptions = (watchOptions = {}) => {
|
|
@@ -1380,10 +1381,10 @@ class Server {
|
|
|
1380
1381
|
Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
|
|
1381
1382
|
Object.prototype.hasOwnProperty.call(options.proxy, "router")
|
|
1382
1383
|
) {
|
|
1383
|
-
/** @type {
|
|
1384
|
+
/** @type {ProxyConfigArray} */
|
|
1384
1385
|
(options.proxy) = [/** @type {ProxyConfigMap} */ (options.proxy)];
|
|
1385
1386
|
} else {
|
|
1386
|
-
/** @type {
|
|
1387
|
+
/** @type {ProxyConfigArray} */
|
|
1387
1388
|
(options.proxy) = Object.keys(options.proxy).map(
|
|
1388
1389
|
/**
|
|
1389
1390
|
* @param {string} context
|
|
@@ -1421,50 +1422,48 @@ class Server {
|
|
|
1421
1422
|
}
|
|
1422
1423
|
}
|
|
1423
1424
|
|
|
1424
|
-
/** @type {
|
|
1425
|
+
/** @type {ProxyConfigArray} */
|
|
1425
1426
|
(options.proxy) =
|
|
1426
|
-
/** @type {
|
|
1427
|
-
(options.proxy).map(
|
|
1427
|
+
/** @type {ProxyConfigArray} */
|
|
1428
|
+
(options.proxy).map((item) => {
|
|
1429
|
+
if (typeof item === "function") {
|
|
1430
|
+
return item;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1428
1433
|
/**
|
|
1429
|
-
* @param {
|
|
1430
|
-
* @returns {
|
|
1434
|
+
* @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level
|
|
1435
|
+
* @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined}
|
|
1431
1436
|
*/
|
|
1432
|
-
(
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
*/
|
|
1437
|
-
const getLogLevelForProxy = (level) => {
|
|
1438
|
-
if (level === "none") {
|
|
1439
|
-
return "silent";
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
if (level === "log") {
|
|
1443
|
-
return "info";
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
if (level === "verbose") {
|
|
1447
|
-
return "debug";
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
return level;
|
|
1451
|
-
};
|
|
1437
|
+
const getLogLevelForProxy = (level) => {
|
|
1438
|
+
if (level === "none") {
|
|
1439
|
+
return "silent";
|
|
1440
|
+
}
|
|
1452
1441
|
|
|
1453
|
-
if (
|
|
1454
|
-
|
|
1455
|
-
compilerOptions.infrastructureLogging
|
|
1456
|
-
? compilerOptions.infrastructureLogging.level
|
|
1457
|
-
: "info"
|
|
1458
|
-
);
|
|
1442
|
+
if (level === "log") {
|
|
1443
|
+
return "info";
|
|
1459
1444
|
}
|
|
1460
1445
|
|
|
1461
|
-
if (
|
|
1462
|
-
|
|
1446
|
+
if (level === "verbose") {
|
|
1447
|
+
return "debug";
|
|
1463
1448
|
}
|
|
1464
1449
|
|
|
1465
|
-
return
|
|
1450
|
+
return level;
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
if (typeof item.logLevel === "undefined") {
|
|
1454
|
+
item.logLevel = getLogLevelForProxy(
|
|
1455
|
+
compilerOptions.infrastructureLogging
|
|
1456
|
+
? compilerOptions.infrastructureLogging.level
|
|
1457
|
+
: "info"
|
|
1458
|
+
);
|
|
1466
1459
|
}
|
|
1467
|
-
|
|
1460
|
+
|
|
1461
|
+
if (typeof item.logProvider === "undefined") {
|
|
1462
|
+
item.logProvider = () => this.logger;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
return item;
|
|
1466
|
+
});
|
|
1468
1467
|
}
|
|
1469
1468
|
|
|
1470
1469
|
if (typeof options.setupExitSignals === "undefined") {
|
|
@@ -2124,7 +2123,7 @@ class Server {
|
|
|
2124
2123
|
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
2125
2124
|
|
|
2126
2125
|
/**
|
|
2127
|
-
* @param {
|
|
2126
|
+
* @param {ProxyConfigArrayItem} proxyConfig
|
|
2128
2127
|
* @returns {RequestHandler | undefined}
|
|
2129
2128
|
*/
|
|
2130
2129
|
const getProxyMiddleware = (proxyConfig) => {
|
|
@@ -2160,93 +2159,91 @@ class Server {
|
|
|
2160
2159
|
* }
|
|
2161
2160
|
* ]
|
|
2162
2161
|
*/
|
|
2163
|
-
/** @type {
|
|
2164
|
-
(this.options.proxy).forEach(
|
|
2162
|
+
/** @type {ProxyConfigArray} */
|
|
2163
|
+
(this.options.proxy).forEach((proxyConfigOrCallback) => {
|
|
2165
2164
|
/**
|
|
2166
|
-
* @
|
|
2165
|
+
* @type {RequestHandler}
|
|
2167
2166
|
*/
|
|
2168
|
-
|
|
2169
|
-
/**
|
|
2170
|
-
* @type {RequestHandler}
|
|
2171
|
-
*/
|
|
2172
|
-
let proxyMiddleware;
|
|
2167
|
+
let proxyMiddleware;
|
|
2173
2168
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2169
|
+
let proxyConfig =
|
|
2170
|
+
typeof proxyConfigOrCallback === "function"
|
|
2171
|
+
? proxyConfigOrCallback()
|
|
2172
|
+
: proxyConfigOrCallback;
|
|
2178
2173
|
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2174
|
+
proxyMiddleware =
|
|
2175
|
+
/** @type {RequestHandler} */
|
|
2176
|
+
(getProxyMiddleware(proxyConfig));
|
|
2182
2177
|
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2178
|
+
if (proxyConfig.ws) {
|
|
2179
|
+
this.webSocketProxies.push(proxyMiddleware);
|
|
2180
|
+
}
|
|
2186
2181
|
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
}
|
|
2182
|
+
/**
|
|
2183
|
+
* @param {Request} req
|
|
2184
|
+
* @param {Response} res
|
|
2185
|
+
* @param {NextFunction} next
|
|
2186
|
+
* @returns {Promise<void>}
|
|
2187
|
+
*/
|
|
2188
|
+
const handler = async (req, res, next) => {
|
|
2189
|
+
if (typeof proxyConfigOrCallback === "function") {
|
|
2190
|
+
const newProxyConfig = proxyConfigOrCallback(req, res, next);
|
|
2191
|
+
|
|
2192
|
+
if (newProxyConfig !== proxyConfig) {
|
|
2193
|
+
proxyConfig = newProxyConfig;
|
|
2194
|
+
proxyMiddleware =
|
|
2195
|
+
/** @type {RequestHandler} */
|
|
2196
|
+
(getProxyMiddleware(proxyConfig));
|
|
2203
2197
|
}
|
|
2198
|
+
}
|
|
2204
2199
|
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
}
|
|
2200
|
+
// - Check if we have a bypass function defined
|
|
2201
|
+
// - In case the bypass function is defined we'll retrieve the
|
|
2202
|
+
// bypassUrl from it otherwise bypassUrl would be null
|
|
2203
|
+
// TODO remove in the next major in favor `context` and `router` options
|
|
2204
|
+
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
|
|
2205
|
+
const bypassUrl = isByPassFuncDefined
|
|
2206
|
+
? await /** @type {ByPass} */ (proxyConfig.bypass)(
|
|
2207
|
+
req,
|
|
2208
|
+
res,
|
|
2209
|
+
proxyConfig
|
|
2210
|
+
)
|
|
2211
|
+
: null;
|
|
2212
|
+
|
|
2213
|
+
if (typeof bypassUrl === "boolean") {
|
|
2214
|
+
// skip the proxy
|
|
2215
|
+
// @ts-ignore
|
|
2216
|
+
req.url = null;
|
|
2217
|
+
next();
|
|
2218
|
+
} else if (typeof bypassUrl === "string") {
|
|
2219
|
+
// byPass to that url
|
|
2220
|
+
req.url = bypassUrl;
|
|
2221
|
+
next();
|
|
2222
|
+
} else if (proxyMiddleware) {
|
|
2223
|
+
return proxyMiddleware(req, res, next);
|
|
2224
|
+
} else {
|
|
2225
|
+
next();
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2230
2228
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
);
|
|
2229
|
+
middlewares.push({
|
|
2230
|
+
name: "http-proxy-middleware",
|
|
2231
|
+
middleware: handler,
|
|
2232
|
+
});
|
|
2233
|
+
// Also forward error requests to the proxy so it can handle them.
|
|
2234
|
+
middlewares.push({
|
|
2235
|
+
name: "http-proxy-middleware-error-handler",
|
|
2236
|
+
middleware:
|
|
2237
|
+
/**
|
|
2238
|
+
* @param {Error} error
|
|
2239
|
+
* @param {Request} req
|
|
2240
|
+
* @param {Response} res
|
|
2241
|
+
* @param {NextFunction} next
|
|
2242
|
+
* @returns {any}
|
|
2243
|
+
*/
|
|
2244
|
+
(error, req, res, next) => handler(req, res, next),
|
|
2245
|
+
});
|
|
2246
|
+
});
|
|
2250
2247
|
|
|
2251
2248
|
middlewares.push({
|
|
2252
2249
|
name: "webpack-dev-middleware",
|