From efec2f5bfb5ff4b99258b12317aa0d922836738e Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 13 Jan 2022 13:01:23 +0300 Subject: [PATCH] fix: types for the `proxy` option (#4173) --- lib/Server.js | 244 +++++++++++++++-------------- types/lib/Server.d.ts | 350 +++++++++++++++++++++++------------------- 2 files changed, 311 insertions(+), 283 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index d597efbd48..291c984418 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -110,22 +110,22 @@ const schema = require("./options.json"); */ /** - * @typedef {{ [url: string]: string | HttpProxyMiddlewareOptions }} ProxyConfigMap + * @callback ByPass + * @param {Request} req + * @param {Response} res + * @param {ProxyConfigArrayItem} proxyConfig */ /** - * @typedef {HttpProxyMiddlewareOptions[]} ProxyArray + * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem */ /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArray} proxyConfig + * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray */ /** - * @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray + * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap */ /** @@ -194,7 +194,7 @@ const schema = require("./options.json"); * @property {boolean} [http2] * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] * @property {boolean | string | Open | Array} [open] * @property {boolean} [setupExitSignals] * @property {boolean | ClientConfiguration} [client] @@ -1380,10 +1380,10 @@ class Server { Object.prototype.hasOwnProperty.call(options.proxy, "target") || Object.prototype.hasOwnProperty.call(options.proxy, "router") ) { - /** @type {ProxyArray} */ + /** @type {ProxyConfigArray} */ (options.proxy) = [/** @type {ProxyConfigMap} */ (options.proxy)]; } else { - /** @type {ProxyArray} */ + /** @type {ProxyConfigArray} */ (options.proxy) = Object.keys(options.proxy).map( /** * @param {string} context @@ -1421,50 +1421,48 @@ class Server { } } - /** @type {ProxyArray} */ + /** @type {ProxyConfigArray} */ (options.proxy) = - /** @type {ProxyArray} */ - (options.proxy).map( + /** @type {ProxyConfigArray} */ + (options.proxy).map((item) => { + if (typeof item === "function") { + return item; + } + /** - * @param {HttpProxyMiddlewareOptions} item - * @returns {HttpProxyMiddlewareOptions} + * @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level + * @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined} */ - (item) => { - /** - * @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level - * @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined} - */ - const getLogLevelForProxy = (level) => { - if (level === "none") { - return "silent"; - } - - if (level === "log") { - return "info"; - } - - if (level === "verbose") { - return "debug"; - } - - return level; - }; + const getLogLevelForProxy = (level) => { + if (level === "none") { + return "silent"; + } - if (typeof item.logLevel === "undefined") { - item.logLevel = getLogLevelForProxy( - compilerOptions.infrastructureLogging - ? compilerOptions.infrastructureLogging.level - : "info" - ); + if (level === "log") { + return "info"; } - if (typeof item.logProvider === "undefined") { - item.logProvider = () => this.logger; + if (level === "verbose") { + return "debug"; } - return item; + return level; + }; + + if (typeof item.logLevel === "undefined") { + item.logLevel = getLogLevelForProxy( + compilerOptions.infrastructureLogging + ? compilerOptions.infrastructureLogging.level + : "info" + ); } - ); + + if (typeof item.logProvider === "undefined") { + item.logProvider = () => this.logger; + } + + return item; + }); } if (typeof options.setupExitSignals === "undefined") { @@ -2124,7 +2122,7 @@ class Server { const { createProxyMiddleware } = require("http-proxy-middleware"); /** - * @param {ProxyConfigArray} proxyConfig + * @param {ProxyConfigArrayItem} proxyConfig * @returns {RequestHandler | undefined} */ const getProxyMiddleware = (proxyConfig) => { @@ -2160,93 +2158,91 @@ class Server { * } * ] */ - /** @type {ProxyArray} */ - (this.options.proxy).forEach( + /** @type {ProxyConfigArray} */ + (this.options.proxy).forEach((proxyConfigOrCallback) => { /** - * @param {any} proxyConfigOrCallback + * @type {RequestHandler} */ - (proxyConfigOrCallback) => { - /** - * @type {RequestHandler} - */ - let proxyMiddleware; + let proxyMiddleware; - let proxyConfig = - typeof proxyConfigOrCallback === "function" - ? proxyConfigOrCallback() - : proxyConfigOrCallback; + let proxyConfig = + typeof proxyConfigOrCallback === "function" + ? proxyConfigOrCallback() + : proxyConfigOrCallback; - proxyMiddleware = - /** @type {RequestHandler} */ - (getProxyMiddleware(proxyConfig)); + proxyMiddleware = + /** @type {RequestHandler} */ + (getProxyMiddleware(proxyConfig)); - if (proxyConfig.ws) { - this.webSocketProxies.push(proxyMiddleware); - } + if (proxyConfig.ws) { + this.webSocketProxies.push(proxyMiddleware); + } - /** - * @param {Request} req - * @param {Response} res - * @param {NextFunction} next - * @returns {Promise} - */ - const handler = async (req, res, next) => { - if (typeof proxyConfigOrCallback === "function") { - const newProxyConfig = proxyConfigOrCallback(req, res, next); - - if (newProxyConfig !== proxyConfig) { - proxyConfig = newProxyConfig; - proxyMiddleware = - /** @type {RequestHandler} */ - (getProxyMiddleware(proxyConfig)); - } + /** + * @param {Request} req + * @param {Response} res + * @param {NextFunction} next + * @returns {Promise} + */ + const handler = async (req, res, next) => { + if (typeof proxyConfigOrCallback === "function") { + const newProxyConfig = proxyConfigOrCallback(req, res, next); + + if (newProxyConfig !== proxyConfig) { + proxyConfig = newProxyConfig; + proxyMiddleware = + /** @type {RequestHandler} */ + (getProxyMiddleware(proxyConfig)); } + } - // - Check if we have a bypass function defined - // - In case the bypass function is defined we'll retrieve the - // bypassUrl from it otherwise bypassUrl would be null - // TODO remove in the next major in favor `context` and `router` options - const isByPassFuncDefined = - typeof proxyConfig.bypass === "function"; - const bypassUrl = isByPassFuncDefined - ? await proxyConfig.bypass(req, res, proxyConfig) - : null; - - if (typeof bypassUrl === "boolean") { - // skip the proxy - // @ts-ignore - req.url = null; - next(); - } else if (typeof bypassUrl === "string") { - // byPass to that url - req.url = bypassUrl; - next(); - } else if (proxyMiddleware) { - return proxyMiddleware(req, res, next); - } else { - next(); - } - }; + // - Check if we have a bypass function defined + // - In case the bypass function is defined we'll retrieve the + // bypassUrl from it otherwise bypassUrl would be null + // TODO remove in the next major in favor `context` and `router` options + const isByPassFuncDefined = typeof proxyConfig.bypass === "function"; + const bypassUrl = isByPassFuncDefined + ? await /** @type {ByPass} */ (proxyConfig.bypass)( + req, + res, + proxyConfig + ) + : null; + + if (typeof bypassUrl === "boolean") { + // skip the proxy + // @ts-ignore + req.url = null; + next(); + } else if (typeof bypassUrl === "string") { + // byPass to that url + req.url = bypassUrl; + next(); + } else if (proxyMiddleware) { + return proxyMiddleware(req, res, next); + } else { + next(); + } + }; - middlewares.push({ - name: "http-proxy-middleware", - middleware: handler, - }); - // Also forward error requests to the proxy so it can handle them. - middlewares.push({ - name: "http-proxy-middleware-error-handler", - middleware: - /** - * @param {Error} error - * @param {Request} req - * @param {Response} res - * @param {NextFunction} next - * @returns {any} - */ - (error, req, res, next) => handler(req, res, next), - }); - } - ); + middlewares.push({ + name: "http-proxy-middleware", + middleware: handler, + }); + // Also forward error requests to the proxy so it can handle them. + middlewares.push({ + name: "http-proxy-middleware-error-handler", + middleware: + /** + * @param {Error} error + * @param {Request} req + * @param {Response} res + * @param {NextFunction} next + * @returns {any} + */ + (error, req, res, next) => handler(req, res, next), + }); + }); middlewares.push({ name: "webpack-dev-middleware", diff --git a/types/lib/Server.d.ts b/types/lib/Server.d.ts index fe00c6cd7e..11ccc3dae4 100644 --- a/types/lib/Server.d.ts +++ b/types/lib/Server.d.ts @@ -97,19 +97,19 @@ declare class Server { * @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation */ /** - * @typedef {{ [url: string]: string | HttpProxyMiddlewareOptions }} ProxyConfigMap + * @callback ByPass + * @param {Request} req + * @param {Response} res + * @param {ProxyConfigArrayItem} proxyConfig */ /** - * @typedef {HttpProxyMiddlewareOptions[]} ProxyArray + * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem */ /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArray} proxyConfig + * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray */ /** - * @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray + * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap */ /** * @typedef {Object} OpenApp @@ -170,7 +170,7 @@ declare class Server { * @property {boolean} [http2] * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] * @property {boolean | string | Open | Array} [open] * @property {boolean} [setupExitSignals] * @property {boolean | ClientConfiguration} [client] @@ -270,19 +270,19 @@ declare class Server { * @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation */ /** - * @typedef {{ [url: string]: string | HttpProxyMiddlewareOptions }} ProxyConfigMap + * @callback ByPass + * @param {Request} req + * @param {Response} res + * @param {ProxyConfigArrayItem} proxyConfig */ /** - * @typedef {HttpProxyMiddlewareOptions[]} ProxyArray + * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem */ /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArray} proxyConfig + * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray */ /** - * @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray + * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap */ /** * @typedef {Object} OpenApp @@ -343,7 +343,7 @@ declare class Server { * @property {boolean} [http2] * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] * @property {boolean | string | Open | Array} [open] * @property {boolean} [setupExitSignals] * @property {boolean | ClientConfiguration} [client] @@ -423,6 +423,11 @@ declare class Server { path: string; }[]; description: string; + /** + * @typedef {Object} Open + * @property {string | string[] | OpenApp} [app] + * @property {string | string[]} [target] + */ negatedDescription: string; simpleType: string; multiple: boolean; @@ -439,6 +444,51 @@ declare class Server { | { type: string; multiple: boolean; + /** + * @typedef {Object} ClientConfiguration + * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] + * @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay] + * @property {boolean} [progress] + * @property {boolean | number} [reconnect] + * @property {"ws" | "sockjs" | string} [webSocketTransport] + * @property {string | WebSocketURL} [webSocketURL] + */ + /** + * @typedef {Array<{ key: string; value: string }> | Record} Headers + */ + /** + * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware + */ + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean} [setupExitSignals] + * @property {boolean | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ description: string; path: string; } @@ -500,7 +550,7 @@ declare class Server { }[]; description: string; simpleType: string; - multiple: boolean; + /** @type {Compiler | MultiCompiler} */ multiple: boolean; }; "client-web-socket-url-protocol": { configs: ( @@ -530,10 +580,6 @@ declare class Server { path: string; }[]; description: string; - /** - * @private - * @type {string | undefined} - */ simpleType: string; multiple: boolean; }; @@ -541,6 +587,10 @@ declare class Server { configs: { type: string; multiple: boolean; + /** + * @private + * @type {string | undefined} + */ description: string; path: string; }[]; @@ -608,10 +658,6 @@ declare class Server { description: string; path: string; }[]; - /** - * @param {Host} hostname - * @returns {Promise} - */ description: string; negatedDescription: string; simpleType: string; @@ -659,11 +705,12 @@ declare class Server { path: string; }[]; description: string; - /** - * @type {string[]} - */ simpleType: string; multiple: boolean; + /** + * @private + * @param {Compiler} compiler + */ }; "https-cacert-reset": { configs: { @@ -679,7 +726,7 @@ declare class Server { "https-cert": { configs: { type: string; - /** @type {ClientConfiguration} */ multiple: boolean; + multiple: boolean; description: string; path: string; }[]; @@ -718,8 +765,9 @@ declare class Server { }[]; description: string; multiple: boolean; - simpleType: string; + simpleType: string /** @type {number | string} */; }; + /** @type {number | string} */ "https-key": { configs: { type: string; @@ -745,6 +793,7 @@ declare class Server { "https-passphrase": { configs: { type: string; + /** @type {string} */ multiple: boolean; description: string; path: string; @@ -791,6 +840,12 @@ declare class Server { configs: ( | { type: string; + /** + * prependEntry Method for webpack 4 + * @param {any} originalEntry + * @param {any} newAdditionalEntries + * @returns {any} + */ multiple: boolean; description: string; path: string; @@ -810,14 +865,14 @@ declare class Server { "live-reload": { configs: { type: string; - /** @type {Object} */ multiple: boolean; + multiple: boolean; description: string; path: string; }[]; description: string; negatedDescription: string; simpleType: string; - multiple: boolean /** @type {any} */; + multiple: boolean; }; "magic-html": { configs: { @@ -919,6 +974,7 @@ declare class Server { path: string; } | { + /** @type {NormalizedStatic} */ type: string; values: string[]; multiple: boolean; @@ -1084,13 +1140,14 @@ declare class Server { multiple: boolean; simpleType: string; }; + /** @type {ServerConfiguration} */ "server-type": { configs: { description: string; multiple: boolean; path: string; type: string; - values: string[]; + values: string[] /** @type {ServerOptions} */; }[]; description: string; multiple: boolean; @@ -1115,7 +1172,6 @@ declare class Server { path: string; }[]; description: string; - /** @type {any} */ simpleType: string; multiple: boolean; }; @@ -1123,7 +1179,7 @@ declare class Server { configs: { type: string; multiple: boolean; - description: string; + /** @type {any} */ description: string; path: string; }[]; description: string; @@ -1135,6 +1191,7 @@ declare class Server { type: string; multiple: boolean; description: string; + /** @type {any} */ path: string; }[]; description: string; @@ -1232,6 +1289,7 @@ declare class Server { multiple: boolean; path: string; type: string; + /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ values: string[]; } | { @@ -1407,19 +1465,19 @@ declare class Server { * @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation */ /** - * @typedef {{ [url: string]: string | HttpProxyMiddlewareOptions }} ProxyConfigMap + * @callback ByPass + * @param {Request} req + * @param {Response} res + * @param {ProxyConfigArrayItem} proxyConfig */ /** - * @typedef {HttpProxyMiddlewareOptions[]} ProxyArray + * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem */ /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArray} proxyConfig + * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray */ /** - * @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray + * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap */ /** * @typedef {Object} OpenApp @@ -1480,7 +1538,7 @@ declare class Server { * @property {boolean} [http2] * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] * @property {boolean | string | Open | Array} [open] * @property {boolean} [setupExitSignals] * @property {boolean | ClientConfiguration} [client] @@ -1558,87 +1616,6 @@ declare class Server { link: string; anyOf: ( | { - /** - * @typedef {HttpProxyMiddlewareOptions[]} ProxyArray - */ - /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArray} proxyConfig - */ - /** - * @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray - */ - /** - * @typedef {Object} OpenApp - * @property {string} [name] - * @property {string[]} [arguments] - */ - /** - * @typedef {Object} Open - * @property {string | string[] | OpenApp} [app] - * @property {string | string[]} [target] - */ - /** - * @typedef {Object} NormalizedOpen - * @property {string} target - * @property {import("open").Options} options - */ - /** - * @typedef {Object} WebSocketURL - * @property {string} [hostname] - * @property {string} [password] - * @property {string} [pathname] - * @property {number | string} [port] - * @property {string} [protocol] - * @property {string} [username] - */ - /** - * @typedef {Object} ClientConfiguration - * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] - * @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay] - * @property {boolean} [progress] - * @property {boolean | number} [reconnect] - * @property {"ws" | "sockjs" | string} [webSocketTransport] - * @property {string | WebSocketURL} [webSocketURL] - */ - /** - * @typedef {Array<{ key: string; value: string }> | Record} Headers - */ - /** - * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware - */ - /** - * @typedef {Object} Configuration - * @property {boolean | string} [ipc] - * @property {Host} [host] - * @property {Port} [port] - * @property {boolean | "only"} [hot] - * @property {boolean} [liveReload] - * @property {DevMiddlewareOptions} [devMiddleware] - * @property {boolean} [compress] - * @property {boolean} [magicHtml] - * @property {"auto" | "all" | string | string[]} [allowedHosts] - * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] - * @property {boolean} [setupExitSignals] - * @property {boolean | BonjourOptions} [bonjour] - * @property {string | string[] | WatchFiles | Array} [watchFiles] - * @property {boolean | string | Static | Array} [static] - * @property {boolean | ServerOptions} [https] - * @property {boolean} [http2] - * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] - * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy] - * @property {boolean | string | Open | Array} [open] - * @property {boolean} [setupExitSignals] - * @property {boolean | ClientConfiguration} [client] - * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] - * @property {(devServer: Server) => void} [onAfterSetupMiddleware] - * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] - * @property {(devServer: Server) => void} [onListening] - * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] - */ type: string; minLength: number; additionalProperties?: undefined; @@ -1661,6 +1638,65 @@ declare class Server { description: string; type: string; }; + /** + * @typedef {Object} NormalizedOpen + * @property {string} target + * @property {import("open").Options} options + */ + /** + * @typedef {Object} WebSocketURL + * @property {string} [hostname] + * @property {string} [password] + * @property {string} [pathname] + * @property {number | string} [port] + * @property {string} [protocol] + * @property {string} [username] + */ + /** + * @typedef {Object} ClientConfiguration + * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] + * @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay] + * @property {boolean} [progress] + * @property {boolean | number} [reconnect] + * @property {"ws" | "sockjs" | string} [webSocketTransport] + * @property {string | WebSocketURL} [webSocketURL] + */ + /** + * @typedef {Array<{ key: string; value: string }> | Record} Headers + */ + /** + * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware + */ + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean} [setupExitSignals] + * @property {boolean | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ port: { description: string; anyOf: ( @@ -1815,9 +1851,6 @@ declare class Server { } | { type: string; - /** - * @type {Socket[]} - */ items?: undefined; instanceof?: undefined; } @@ -1840,11 +1873,6 @@ declare class Server { instanceof?: undefined; } | { - /** - * @private - * @returns {StatsOptions} - * @constructor - */ instanceof: string; type?: undefined; } @@ -1883,7 +1911,6 @@ declare class Server { } | { type: string; - /** @type {NetworkInterfaceInfo[]} */ additionalProperties: boolean; instanceof?: undefined; } @@ -1905,6 +1932,10 @@ declare class Server { description: string; }; pfx: { + /** + * @param {"v4" | "v6"} family + * @returns {Promise} + */ anyOf: ( | { type: string; @@ -1922,10 +1953,6 @@ declare class Server { } | { type: string; - /** - * @param {Host} hostname - * @returns {Promise} - */ additionalProperties: boolean; instanceof?: undefined; } @@ -2060,18 +2087,18 @@ declare class Server { LiveReload: { type: string; description: string; - /** @type {{ type: WebSocketServerConfiguration["type"], options: NonNullable }} */ - link: string; + /** @type {ClientConfiguration} */ link: string; }; MagicHTML: { type: string; + /** @type {{ type: WebSocketServerConfiguration["type"], options: NonNullable }} */ description: string; link: string; }; OnAfterSetupMiddleware: { instanceof: string; description: string; - link: string; + /** @type {ServerConfiguration} */ link: string; }; OnBeforeSetupMiddleware: { instanceof: string; @@ -2265,7 +2292,6 @@ declare class Server { }; additionalProperties: boolean; }; - /** @type {any} */ ServerOptions: { type: string; additionalProperties: boolean; @@ -2294,10 +2320,6 @@ declare class Server { } )[]; }; - /** - * @private - * @returns {Compiler["options"]} - */ instanceof?: undefined; } | { @@ -2750,12 +2772,14 @@ declare class Server { onListening: { $ref: string; }; + /** @type {ServerOptions} */ open: { $ref: string; }; port: { - $ref: string /** @type {Array} */; + $ref: string; }; + /** @type {ServerOptions} */ proxy: { $ref: string; }; @@ -3132,10 +3156,10 @@ declare namespace Server { ClientConnection, WebSocketServer, WebSocketServerImplementation, - ProxyConfigMap, - ProxyArray, ByPass, + ProxyConfigArrayItem, ProxyConfigArray, + ProxyConfigMap, OpenApp, Open, NormalizedOpen, @@ -3185,7 +3209,7 @@ type Configuration = { http2?: boolean | undefined; server?: string | ServerConfiguration | undefined; webSocketServer?: string | boolean | WebSocketServerConfiguration | undefined; - proxy?: ProxyConfigMap | ProxyConfigArray | ProxyArray | undefined; + proxy?: ProxyConfigArrayItem | ProxyConfigMap | ProxyConfigArray | undefined; open?: string | boolean | Open | (string | Open)[] | undefined; client?: boolean | ClientConfiguration | undefined; headers?: @@ -3311,20 +3335,28 @@ type WebSocketServer = | (import("sockjs").Server & { close: import("ws").WebSocketServer["close"]; }); -type ProxyConfigMap = { - [url: string]: string | import("http-proxy-middleware").Options; -}; -type ProxyArray = HttpProxyMiddlewareOptions[]; type ByPass = ( req: Request, res: Response, - proxyConfig: ProxyConfigArray + proxyConfig: ProxyConfigArrayItem ) => any; -type ProxyConfigArray = { - path?: string | string[] | undefined; - context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined; -} & HttpProxyMiddlewareOptions & - ByPass; +type ProxyConfigArrayItem = { + path?: HttpProxyMiddlewareOptionsFilter | undefined; + context?: HttpProxyMiddlewareOptionsFilter | undefined; +} & { + bypass?: ByPass; +} & HttpProxyMiddlewareOptions; +type ProxyConfigArray = ( + | ProxyConfigArrayItem + | (( + req?: Request | undefined, + res?: Response | undefined, + next?: NextFunction | undefined + ) => ProxyConfigArrayItem) +)[]; +type ProxyConfigMap = { + [url: string]: string | ProxyConfigArrayItem; +}; type OpenApp = { name?: string | undefined; arguments?: string[] | undefined;