@rspack/dev-server 1.2.1 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +0,0 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/webpack/webpack-dev-server
4
- *
5
- * MIT Licensed
6
- * Author Tobias Koppers @sokra
7
- * Copyright (c) JS Foundation and other contributors
8
- * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
- */
10
- export {};
@@ -1,110 +0,0 @@
1
- "use strict";
2
- /**
3
- * The following code is modified based on
4
- * https://github.com/webpack/webpack-dev-server
5
- *
6
- * MIT Licensed
7
- * Author Tobias Koppers @sokra
8
- * Copyright (c) JS Foundation and other contributors
9
- * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
10
- */
11
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- var desc = Object.getOwnPropertyDescriptor(m, k);
14
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
- desc = { enumerable: true, get: function() { return m[k]; } };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }) : (function(o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- }));
22
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
- Object.defineProperty(o, "default", { enumerable: true, value: v });
24
- }) : function(o, v) {
25
- o["default"] = v;
26
- });
27
- var __importStar = (this && this.__importStar) || function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- const sockjs = __importStar(require("sockjs"));
39
- const BaseServer_1 = __importDefault(require("./BaseServer"));
40
- // Workaround for sockjs@~0.3.19
41
- // sockjs will remove Origin header, however Origin header is required for checking host.
42
- // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
43
- {
44
- const SockjsSession = require('sockjs/lib/transport').Session;
45
- const { decorateConnection } = SockjsSession.prototype;
46
- // eslint-disable-next-line func-names
47
- SockjsSession.prototype.decorateConnection = function (req) {
48
- decorateConnection.call(this, req);
49
- const { connection } = this;
50
- if (connection.headers &&
51
- !('origin' in connection.headers) &&
52
- 'origin' in req.headers) {
53
- connection.headers.origin = req.headers.origin;
54
- }
55
- };
56
- }
57
- class SockJSServer extends BaseServer_1.default {
58
- // options has: error (function), debug (function), server (http/s server), path (string)
59
- constructor(server) {
60
- super(server);
61
- const webSocketServerOptions = this.server.options.webSocketServer.options;
62
- const getSockjsUrl = (options) => {
63
- if (typeof options.sockjsUrl !== 'undefined') {
64
- return options.sockjsUrl;
65
- }
66
- return '/__webpack_dev_server__/sockjs.bundle.js';
67
- };
68
- this.implementation = sockjs.createServer({
69
- // Use provided up-to-date sockjs-client
70
- // eslint-disable-next-line camelcase
71
- sockjs_url: getSockjsUrl(webSocketServerOptions),
72
- // Default logger is very annoy. Limit useless logs.
73
- log: (severity, line) => {
74
- if (severity === 'error') {
75
- this.server.logger.error(line);
76
- }
77
- else if (severity === 'info') {
78
- this.server.logger.log(line);
79
- }
80
- else {
81
- this.server.logger.debug(line);
82
- }
83
- },
84
- });
85
- const getPrefix = (options) => {
86
- if (typeof options.prefix !== 'undefined') {
87
- return options.prefix;
88
- }
89
- return options.path;
90
- };
91
- const options = {
92
- ...webSocketServerOptions,
93
- prefix: getPrefix(webSocketServerOptions),
94
- };
95
- this.implementation.installHandlers(this.server.server, options);
96
- this.implementation.on('connection', (client) => {
97
- // Implement the the same API as for `ws`
98
- client.send = client.write;
99
- client.terminate = client.close;
100
- this.clients.push(client);
101
- client.on('close', () => {
102
- this.clients.splice(this.clients.indexOf(client), 1);
103
- });
104
- });
105
- this.implementation.close = (callback) => {
106
- callback();
107
- };
108
- }
109
- }
110
- module.exports = SockJSServer;