Skip to content

Commit 012d844

Browse files
committed
Merge branch 'next' of github.com:webpack/webpack-dev-server into remove-cli-flags
2 parents 30054fd + ebd7f64 commit 012d844

27 files changed

Lines changed: 545 additions & 1149 deletions

bin/cli-flags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ module.exports = {
790790
multiple: false,
791791
path: "server.type",
792792
type: "enum",
793-
values: ["http", "https", "spdy"],
793+
values: ["http", "https"],
794794
},
795795
],
796796
description: "Allows to set server and options (by default 'http').",

examples/server/spdy/README.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

examples/server/spdy/app.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/server/spdy/ssl/ca.pem

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/server/spdy/ssl/server.crt

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/server/spdy/ssl/server.key

Lines changed: 0 additions & 28 deletions
This file was deleted.
-2.41 KB
Binary file not shown.

examples/server/spdy/webpack.config.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/Server.js

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const schema = require("./options.json");
5050
/** @typedef {(err: EXPECTED_ANY, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void} ErrorHandleFunction */
5151
/** @typedef {SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction} HandleFunction */
5252

53-
/** @typedef {import("https").ServerOptions & { spdy?: { plain?: boolean | undefined, ssl?: boolean | undefined, 'x-forwarded-for'?: string | undefined, protocol?: string | undefined, protocols?: string[] | undefined }}} ServerOptions */
53+
/** @typedef {import("https").ServerOptions} ServerOptions */
5454

5555
/**
5656
* @template {BasicApplication} [T=ExpressApplication]
@@ -108,7 +108,7 @@ const schema = require("./options.json");
108108
/**
109109
* @template {BasicApplication} [A=ExpressApplication]
110110
* @template {BasicServer} [S=import("http").Server]
111-
* @typedef {"http" | "https" | "spdy" | "http2" | string | ((serverOptions: ServerOptions, application: A) => S)} ServerType
111+
* @typedef {"http" | "https" | "http2" | string | ((serverOptions: ServerOptions, application: A) => S)} ServerType
112112
*/
113113

114114
/**
@@ -1107,18 +1107,7 @@ class Server {
11071107

11081108
const serverOptions = /** @type {ServerOptions} */ (options.server.options);
11091109

1110-
if (
1111-
options.server.type === "spdy" &&
1112-
typeof serverOptions.spdy === "undefined"
1113-
) {
1114-
serverOptions.spdy = { protocols: ["h2", "http/1.1"] };
1115-
}
1116-
1117-
if (
1118-
options.server.type === "https" ||
1119-
options.server.type === "http2" ||
1120-
options.server.type === "spdy"
1121-
) {
1110+
if (options.server.type === "https" || options.server.type === "http2") {
11221111
if (typeof serverOptions.requestCert === "undefined") {
11231112
serverOptions.requestCert = false;
11241113
}
@@ -1391,36 +1380,8 @@ class Server {
13911380
return item;
13921381
}
13931382

1394-
/**
1395-
* @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level level
1396-
* @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined} log level for proxy
1397-
*/
1398-
const getLogLevelForProxy = (level) => {
1399-
if (level === "none") {
1400-
return "silent";
1401-
}
1402-
1403-
if (level === "log") {
1404-
return "info";
1405-
}
1406-
1407-
if (level === "verbose") {
1408-
return "debug";
1409-
}
1410-
1411-
return level;
1412-
};
1413-
1414-
if (typeof item.logLevel === "undefined") {
1415-
item.logLevel = getLogLevelForProxy(
1416-
compilerOptions.infrastructureLogging
1417-
? compilerOptions.infrastructureLogging.level
1418-
: "info",
1419-
);
1420-
}
1421-
1422-
if (typeof item.logProvider === "undefined") {
1423-
item.logProvider = () => this.logger;
1383+
if (typeof item.logger === "undefined") {
1384+
item.logger = this.logger;
14241385
}
14251386

14261387
return item;
@@ -2006,7 +1967,7 @@ class Server {
20061967
}
20071968

20081969
// compress is placed last and uses unshift so that it will be the first middleware used
2009-
if (this.options.compress && !isHTTP2) {
1970+
if (this.options.compress) {
20101971
const compression = require("compression");
20111972

20121973
middlewares.push({ name: "compression", middleware: compression() });
@@ -2175,10 +2136,10 @@ class Server {
21752136
if (proxyConfig.target) {
21762137
const context = proxyConfig.context || proxyConfig.path;
21772138

2178-
return createProxyMiddleware(
2179-
/** @type {string} */ (context),
2180-
proxyConfig,
2181-
);
2139+
return createProxyMiddleware({
2140+
...proxyConfig,
2141+
pathFilter: /** @type {string} */ (context),
2142+
});
21822143
}
21832144

21842145
if (proxyConfig.router) {
@@ -3089,6 +3050,32 @@ class Server {
30893050
return false;
30903051
}
30913052

3053+
/**
3054+
* Extracts and normalizes the hostname from a header, removing brackets for IPv6.
3055+
* @param {string} header header value
3056+
* @returns {string|null} hostname or null
3057+
*/
3058+
#parseHostnameFromHeader = function (header) {
3059+
if (!header) return null;
3060+
try {
3061+
// If the header does not have a scheme, prepend // so URL can parse it
3062+
const parseUrl = new URL(
3063+
/^(.+:)?\/\//.test(header) ? header : `//${header}`,
3064+
"http://localhost/",
3065+
);
3066+
3067+
let hostname = parseUrl.hostname;
3068+
// Normalize IPv6: remove brackets if present
3069+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
3070+
hostname = hostname.slice(1, -1);
3071+
}
3072+
3073+
return hostname;
3074+
} catch {
3075+
return null;
3076+
}
3077+
};
3078+
30923079
/**
30933080
* @private
30943081
* @param {{ [key: string]: string | undefined }} headers headers
@@ -3113,15 +3100,7 @@ class Server {
31133100
return true;
31143101
}
31153102

3116-
// use the node url-parser to retrieve the hostname from the host-header.
3117-
// TODO resolve me in the next major release
3118-
// eslint-disable-next-line n/no-deprecated-api
3119-
const { hostname } = url.parse(
3120-
// if header doesn't have scheme, add // for parsing.
3121-
/^(.+:)?\/\//.test(header) ? header : `//${header}`,
3122-
false,
3123-
true,
3124-
);
3103+
const hostname = this.#parseHostnameFromHeader(header);
31253104

31263105
if (hostname === null) {
31273106
return false;
@@ -3135,8 +3114,7 @@ class Server {
31353114
// A note on IPv6 addresses:
31363115
// header will always contain the brackets denoting
31373116
// an IPv6-address in URLs,
3138-
// these are removed from the hostname in url.parse(),
3139-
// so we have the pure IPv6-address in hostname.
3117+
// these aren't removed from the hostname in new URL(),
31403118
// For convenience, always allow localhost (hostname === 'localhost')
31413119
// and its subdomains (hostname.endsWith(".localhost")).
31423120
// allow hostname of listening address (hostname === this.options.host)
@@ -3171,9 +3149,7 @@ class Server {
31713149
return true;
31723150
}
31733151

3174-
// TODO resolve me in the next major release
3175-
// eslint-disable-next-line n/no-deprecated-api
3176-
const origin = url.parse(originHeader, false, true).hostname;
3152+
const origin = this.#parseHostnameFromHeader(originHeader);
31773153

31783154
if (origin === null) {
31793155
return false;
@@ -3193,13 +3169,7 @@ class Server {
31933169
return true;
31943170
}
31953171

3196-
// eslint-disable-next-line n/no-deprecated-api
3197-
const host = url.parse(
3198-
// if hostHeader doesn't have scheme, add // for parsing.
3199-
/^(.+:)?\/\//.test(hostHeader) ? hostHeader : `//${hostHeader}`,
3200-
false,
3201-
true,
3202-
).hostname;
3172+
const host = this.#parseHostnameFromHeader(hostHeader);
32033173

32043174
if (host === null) {
32053175
return false;

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,13 @@
529529
"description": "Allows to set server and options (by default 'http')."
530530
},
531531
"ServerType": {
532-
"enum": ["http", "https", "spdy", "http2"]
532+
"enum": ["http", "https", "http2"]
533533
},
534534
"ServerFn": {
535535
"instanceof": "Function"
536536
},
537537
"ServerEnum": {
538-
"enum": ["http", "https", "spdy", "http2"],
538+
"enum": ["http", "https", "http2"],
539539
"cli": {
540540
"exclude": true
541541
}

0 commit comments

Comments
 (0)