@@ -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 ;
0 commit comments