(parsedURL)
| 675 | * @returns {string} socket URL |
| 676 | */ |
| 677 | const createSocketURL = (parsedURL) => { |
| 678 | let { hostname } = parsedURL; |
| 679 | |
| 680 | // Node.js module parses it as `::` |
| 681 | // `new URL(urlString, [baseURLString])` parses it as '[::]' |
| 682 | const isInAddrAny = |
| 683 | hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]"; |
| 684 | |
| 685 | // why do we need this check? |
| 686 | // hostname n/a for file protocol (example, when using electron, ionic) |
| 687 | // see: https://github.com/webpack/webpack-dev-server/pull/384 |
| 688 | if ( |
| 689 | isInAddrAny && |
| 690 | self.location.hostname && |
| 691 | self.location.protocol.indexOf("http") === 0 |
| 692 | ) { |
| 693 | hostname = self.location.hostname; |
| 694 | } |
| 695 | |
| 696 | let socketURLProtocol = parsedURL.protocol || self.location.protocol; |
| 697 | |
| 698 | // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets. |
| 699 | if ( |
| 700 | socketURLProtocol === "auto:" || |
| 701 | (hostname && isInAddrAny && self.location.protocol === "https:") |
| 702 | ) { |
| 703 | socketURLProtocol = self.location.protocol; |
| 704 | } |
| 705 | |
| 706 | socketURLProtocol = socketURLProtocol.replace( |
| 707 | /^(?:http|.+-extension|file)/i, |
| 708 | "ws", |
| 709 | ); |
| 710 | |
| 711 | let socketURLAuth = ""; |
| 712 | |
| 713 | // `new URL(urlString, [baseURLstring])` doesn't have `auth` property |
| 714 | // Parse authentication credentials in case we need them |
| 715 | if (parsedURL.username) { |
| 716 | socketURLAuth = parsedURL.username; |
| 717 | |
| 718 | // Since HTTP basic authentication does not allow empty username, |
| 719 | // we only include password if the username is not empty. |
| 720 | if (parsedURL.password) { |
| 721 | // Result: <username>:<password> |
| 722 | socketURLAuth = socketURLAuth.concat(":", parsedURL.password); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // In case the host is a raw IPv6 address, it can be enclosed in |
| 727 | // the brackets as the brackets are needed in the final URL string. |
| 728 | // Need to remove those as url.format blindly adds its own set of brackets |
| 729 | // if the host string contains colons. That would lead to non-working |
| 730 | // double brackets (e.g. [[::]]) host |
| 731 | // |
| 732 | // All of these web socket url params are optionally passed in through resourceQuery, |
| 733 | // so we need to fall back to the default if they are not provided |
| 734 | const socketURLHostname = ( |
no test coverage detected
searching dependent graphs…