* @private * @param {Compiler} compiler compiler * @returns {Promise }
(compiler)
| 608 | * @returns {Promise<void>} |
| 609 | */ |
| 610 | async addAdditionalEntries(compiler) { |
| 611 | /** |
| 612 | * @type {string[]} |
| 613 | */ |
| 614 | const additionalEntries = []; |
| 615 | const isWebTarget = Server.isWebTarget(compiler); |
| 616 | |
| 617 | // TODO maybe empty client |
| 618 | if (this.options.client && isWebTarget) { |
| 619 | let webSocketURLStr = ""; |
| 620 | |
| 621 | if (this.options.webSocketServer) { |
| 622 | const webSocketURL = |
| 623 | /** @type {WebSocketURL} */ |
| 624 | ( |
| 625 | /** @type {ClientConfiguration} */ |
| 626 | (this.options.client).webSocketURL |
| 627 | ); |
| 628 | const webSocketServer = |
| 629 | /** @type {{ type: WebSocketServerConfiguration["type"], options: NonNullable<WebSocketServerConfiguration["options"]> }} */ |
| 630 | (this.options.webSocketServer); |
| 631 | const searchParams = new URLSearchParams(); |
| 632 | |
| 633 | /** @type {string} */ |
| 634 | let protocol; |
| 635 | |
| 636 | // We are proxying dev server and need to specify custom `hostname` |
| 637 | if (typeof webSocketURL.protocol !== "undefined") { |
| 638 | protocol = webSocketURL.protocol; |
| 639 | } else { |
| 640 | protocol = this.isTlsServer ? "wss:" : "ws:"; |
| 641 | } |
| 642 | |
| 643 | searchParams.set("protocol", protocol); |
| 644 | |
| 645 | if (typeof webSocketURL.username !== "undefined") { |
| 646 | searchParams.set("username", webSocketURL.username); |
| 647 | } |
| 648 | |
| 649 | if (typeof webSocketURL.password !== "undefined") { |
| 650 | searchParams.set("password", webSocketURL.password); |
| 651 | } |
| 652 | |
| 653 | /** @type {string} */ |
| 654 | let hostname; |
| 655 | |
| 656 | const isWebSocketServerHostDefined = |
| 657 | typeof webSocketServer.options.host !== "undefined"; |
| 658 | const isWebSocketServerPortDefined = |
| 659 | typeof webSocketServer.options.port !== "undefined"; |
| 660 | |
| 661 | // We are proxying dev server and need to specify custom `hostname` |
| 662 | if (typeof webSocketURL.hostname !== "undefined") { |
| 663 | hostname = webSocketURL.hostname; |
| 664 | } |
| 665 | // Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname` |
| 666 | else if (isWebSocketServerHostDefined) { |
| 667 | hostname = webSocketServer.options.host; |
no test coverage detected