MCPcopy
hub / github.com/webpack/webpack-dev-server / createWebSocketServer

Method createWebSocketServer

lib/Server.js:2590–2700  ·  view source on GitHub ↗

* @private * @returns {Promise }

()

Source from the content-addressed store, hash-verified

2588 * @returns {Promise<void>}
2589 */
2590 async createWebSocketServer() {
2591 /** @type {WebSocketServerImplementation | undefined | null} */
2592 this.webSocketServer = new (await this.getServerTransport())(this);
2593
2594 /** @type {WebSocketServerImplementation} */
2595 (this.webSocketServer).implementation.on(
2596 "connection",
2597 /**
2598 * @param {ClientConnection} client client
2599 * @param {IncomingMessage} request request
2600 */
2601 (client, request) => {
2602 /** @type {{ [key: string]: string | undefined } | undefined} */
2603 const headers =
2604 typeof request !== "undefined"
2605 ? /** @type {{ [key: string]: string | undefined }} */
2606 (request.headers)
2607 : undefined;
2608
2609 if (!headers) {
2610 this.logger.warn(
2611 'webSocketServer implementation must pass headers for the "connection" event',
2612 );
2613 }
2614
2615 if (
2616 !headers ||
2617 !this.isValidHost(headers, "host") ||
2618 !this.isValidHost(headers, "origin") ||
2619 !this.isSameOrigin(headers)
2620 ) {
2621 this.sendMessage([client], "error", "Invalid Host/Origin header");
2622
2623 // With https enabled, the sendMessage above is encrypted asynchronously so not yet sent
2624 // Terminate would prevent it sending, so use close to allow it to be sent
2625 client.close();
2626
2627 return;
2628 }
2629
2630 if (this.options.hot === true || this.options.hot === "only") {
2631 this.sendMessage([client], "hot");
2632 }
2633
2634 if (this.options.liveReload) {
2635 this.sendMessage([client], "liveReload");
2636 }
2637
2638 if (
2639 this.options.client &&
2640 /** @type {ClientConfiguration} */
2641 (this.options.client).progress
2642 ) {
2643 this.sendMessage(
2644 [client],
2645 "progress",
2646 /** @type {ClientConfiguration} */
2647 (this.options.client).progress,

Callers 1

listenMethod · 0.95

Calls 7

getServerTransportMethod · 0.95
isValidHostMethod · 0.95
isSameOriginMethod · 0.95
sendMessageMethod · 0.95
sendStatsMethod · 0.95
getStatsMethod · 0.95
encodeOverlaySettingsFunction · 0.85

Tested by

no test coverage detected