webpack-dev-server 3.3.1 → 3.5.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.
package/lib/options.json CHANGED
@@ -1,33 +1,61 @@
1
1
  {
2
2
  "type": "object",
3
3
  "properties": {
4
- "serveIndex": {
5
- "type": "boolean"
6
- },
7
- "hot": {
8
- "type": "boolean"
4
+ "after": {
5
+ "instanceof": "Function"
9
6
  },
10
- "hotOnly": {
11
- "type": "boolean"
7
+ "allowedHosts": {
8
+ "type": "array",
9
+ "items": {
10
+ "type": "string"
11
+ }
12
12
  },
13
- "lazy": {
14
- "type": "boolean"
13
+ "before": {
14
+ "instanceof": "Function"
15
15
  },
16
16
  "bonjour": {
17
17
  "type": "boolean"
18
18
  },
19
- "host": {
19
+ "ca": {
20
20
  "anyOf": [
21
21
  {
22
22
  "type": "string"
23
23
  },
24
24
  {
25
- "type": "null"
25
+ "instanceof": "Buffer"
26
26
  }
27
27
  ]
28
28
  },
29
- "port": {
29
+ "cert": {
30
+ "anyOf": [
31
+ {
32
+ "type": "string"
33
+ },
34
+ {
35
+ "instanceof": "Buffer"
36
+ }
37
+ ]
38
+ },
39
+ "clientLogLevel": {
40
+ "enum": [
41
+ "info",
42
+ "warn",
43
+ "error",
44
+ "debug",
45
+ "trace",
46
+ "silent",
47
+ "none",
48
+ "warning"
49
+ ]
50
+ },
51
+ "compress": {
52
+ "type": "boolean"
53
+ },
54
+ "contentBase": {
30
55
  "anyOf": [
56
+ {
57
+ "enum": [false]
58
+ },
31
59
  {
32
60
  "type": "number"
33
61
  },
@@ -35,11 +63,18 @@
35
63
  "type": "string"
36
64
  },
37
65
  {
38
- "type": "null"
66
+ "type": "array",
67
+ "items": {
68
+ "type": "string"
69
+ },
70
+ "minItems": 1
39
71
  }
40
72
  ]
41
73
  },
42
- "allowedHosts": {
74
+ "disableHostCheck": {
75
+ "type": "boolean"
76
+ },
77
+ "features": {
43
78
  "type": "array",
44
79
  "items": {
45
80
  "type": "string"
@@ -58,89 +93,78 @@
58
93
  }
59
94
  ]
60
95
  },
61
- "publicPath": {
62
- "type": "string"
63
- },
64
- "socket": {
65
- "type": "string"
66
- },
67
- "sockPath": {
68
- "type": "string"
96
+ "fs": {
97
+ "type": "object"
69
98
  },
70
- "watchOptions": {
99
+ "headers": {
71
100
  "type": "object"
72
101
  },
73
- "writeToDisk": {
102
+ "historyApiFallback": {
74
103
  "anyOf": [
75
104
  {
76
105
  "type": "boolean"
77
106
  },
78
107
  {
79
- "instanceof": "Function"
108
+ "type": "object"
80
109
  }
81
110
  ]
82
111
  },
83
- "headers": {
84
- "type": "object"
85
- },
86
- "logLevel": {
87
- "enum": ["info", "warn", "error", "debug", "trace", "silent"]
88
- },
89
- "clientLogLevel": {
90
- "enum": ["none", "info", "error", "warning"]
91
- },
92
- "overlay": {
112
+ "host": {
93
113
  "anyOf": [
94
114
  {
95
- "type": "boolean"
115
+ "type": "string"
96
116
  },
97
117
  {
98
- "type": "object",
99
- "properties": {
100
- "errors": {
101
- "type": "boolean"
102
- },
103
- "warnings": {
104
- "type": "boolean"
105
- }
106
- }
118
+ "type": "null"
107
119
  }
108
120
  ]
109
121
  },
110
- "progress": {
122
+ "hot": {
111
123
  "type": "boolean"
112
124
  },
113
- "key": {
125
+ "hotOnly": {
126
+ "type": "boolean"
127
+ },
128
+ "http2": {
129
+ "type": "boolean"
130
+ },
131
+ "https": {
114
132
  "anyOf": [
115
133
  {
116
- "type": "string"
134
+ "type": "object"
117
135
  },
118
136
  {
119
- "instanceof": "Buffer"
137
+ "type": "boolean"
120
138
  }
121
139
  ]
122
140
  },
123
- "cert": {
141
+ "index": {
142
+ "type": "string"
143
+ },
144
+ "injectClient": {
124
145
  "anyOf": [
125
146
  {
126
- "type": "string"
147
+ "type": "boolean"
127
148
  },
128
149
  {
129
- "instanceof": "Buffer"
150
+ "instanceof": "Function"
130
151
  }
131
152
  ]
132
153
  },
133
- "ca": {
154
+ "injectHot": {
134
155
  "anyOf": [
135
156
  {
136
- "type": "string"
157
+ "type": "boolean"
137
158
  },
138
159
  {
139
- "instanceof": "Buffer"
160
+ "instanceof": "Function"
140
161
  }
141
162
  ]
142
163
  },
143
- "pfx": {
164
+ "inline": {
165
+ "type": "boolean"
166
+ },
167
+ "key": {
144
168
  "anyOf": [
145
169
  {
146
170
  "type": "string"
@@ -150,80 +174,88 @@
150
174
  }
151
175
  ]
152
176
  },
153
- "pfxPassphrase": {
154
- "type": "string"
177
+ "lazy": {
178
+ "type": "boolean"
155
179
  },
156
- "requestCert": {
180
+ "liveReload": {
157
181
  "type": "boolean"
158
182
  },
159
- "inline": {
183
+ "log": {
184
+ "instanceof": "Function"
185
+ },
186
+ "logLevel": {
187
+ "enum": ["info", "warn", "error", "debug", "trace", "silent"]
188
+ },
189
+ "logTime": {
160
190
  "type": "boolean"
161
191
  },
162
- "disableHostCheck": {
192
+ "mimeTypes": {
193
+ "type": "object"
194
+ },
195
+ "noInfo": {
163
196
  "type": "boolean"
164
197
  },
165
- "public": {
166
- "type": "string"
198
+ "onListening": {
199
+ "instanceof": "Function"
167
200
  },
168
- "https": {
201
+ "open": {
169
202
  "anyOf": [
170
203
  {
171
- "type": "object"
204
+ "type": "string"
172
205
  },
173
206
  {
174
207
  "type": "boolean"
175
208
  }
176
209
  ]
177
210
  },
178
- "http2": {
179
- "type": "boolean"
211
+ "openPage": {
212
+ "type": "string"
180
213
  },
181
- "contentBase": {
214
+ "overlay": {
182
215
  "anyOf": [
183
216
  {
184
- "enum": [false]
217
+ "type": "boolean"
185
218
  },
186
219
  {
187
- "type": "number"
188
- },
220
+ "type": "object",
221
+ "properties": {
222
+ "errors": {
223
+ "type": "boolean"
224
+ },
225
+ "warnings": {
226
+ "type": "boolean"
227
+ }
228
+ }
229
+ }
230
+ ]
231
+ },
232
+ "pfx": {
233
+ "anyOf": [
189
234
  {
190
235
  "type": "string"
191
236
  },
192
237
  {
193
- "type": "array",
194
- "items": {
195
- "type": "string"
196
- },
197
- "minItems": 1
238
+ "instanceof": "Buffer"
198
239
  }
199
240
  ]
200
241
  },
201
- "watchContentBase": {
202
- "type": "boolean"
242
+ "pfxPassphrase": {
243
+ "type": "string"
203
244
  },
204
- "open": {
245
+ "port": {
205
246
  "anyOf": [
247
+ {
248
+ "type": "number"
249
+ },
206
250
  {
207
251
  "type": "string"
208
252
  },
209
253
  {
210
- "type": "boolean"
254
+ "type": "null"
211
255
  }
212
256
  ]
213
257
  },
214
- "useLocalIp": {
215
- "type": "boolean"
216
- },
217
- "openPage": {
218
- "type": "string"
219
- },
220
- "features": {
221
- "type": "array",
222
- "items": {
223
- "type": "string"
224
- }
225
- },
226
- "compress": {
258
+ "progress": {
227
259
  "type": "boolean"
228
260
  },
229
261
  "proxy": {
@@ -247,28 +279,55 @@
247
279
  }
248
280
  ]
249
281
  },
250
- "historyApiFallback": {
282
+ "public": {
283
+ "type": "string"
284
+ },
285
+ "publicPath": {
286
+ "type": "string"
287
+ },
288
+ "quiet": {
289
+ "type": "boolean"
290
+ },
291
+ "reporter": {
292
+ "instanceof": "Function"
293
+ },
294
+ "requestCert": {
295
+ "type": "boolean"
296
+ },
297
+ "serveIndex": {
298
+ "type": "boolean"
299
+ },
300
+ "serverSideRender": {
301
+ "type": "boolean"
302
+ },
303
+ "setup": {
304
+ "instanceof": "Function"
305
+ },
306
+ "sockHost": {
307
+ "type": "string"
308
+ },
309
+ "sockPath": {
310
+ "type": "string"
311
+ },
312
+ "sockPort": {
251
313
  "anyOf": [
252
314
  {
253
- "type": "boolean"
315
+ "type": "number"
254
316
  },
255
317
  {
256
- "type": "object"
318
+ "type": "string"
319
+ },
320
+ {
321
+ "type": "null"
257
322
  }
258
323
  ]
259
324
  },
325
+ "socket": {
326
+ "type": "string"
327
+ },
260
328
  "staticOptions": {
261
329
  "type": "object"
262
330
  },
263
- "setup": {
264
- "instanceof": "Function"
265
- },
266
- "before": {
267
- "instanceof": "Function"
268
- },
269
- "after": {
270
- "instanceof": "Function"
271
- },
272
331
  "stats": {
273
332
  "anyOf": [
274
333
  {
@@ -278,92 +337,102 @@
278
337
  "type": "boolean"
279
338
  },
280
339
  {
281
- "enum": ["none", "errors-only", "minimal", "normal", "verbose"]
340
+ "enum": [
341
+ "none",
342
+ "errors-only",
343
+ "errors-warnings",
344
+ "minimal",
345
+ "normal",
346
+ "verbose"
347
+ ]
282
348
  }
283
349
  ]
284
350
  },
285
- "reporter": {
286
- "instanceof": "Function"
287
- },
288
- "logTime": {
289
- "type": "boolean"
290
- },
291
- "noInfo": {
351
+ "useLocalIp": {
292
352
  "type": "boolean"
293
353
  },
294
- "mimeTypes": {
295
- "type": "object"
296
- },
297
- "quiet": {
298
- "type": "boolean"
354
+ "warn": {
355
+ "instanceof": "Function"
299
356
  },
300
- "serverSideRender": {
357
+ "watchContentBase": {
301
358
  "type": "boolean"
302
359
  },
303
- "index": {
304
- "type": "string"
305
- },
306
- "log": {
307
- "instanceof": "Function"
360
+ "watchOptions": {
361
+ "type": "object"
308
362
  },
309
- "warn": {
310
- "instanceof": "Function"
363
+ "writeToDisk": {
364
+ "anyOf": [
365
+ {
366
+ "type": "boolean"
367
+ },
368
+ {
369
+ "instanceof": "Function"
370
+ }
371
+ ]
311
372
  }
312
373
  },
313
374
  "errorMessage": {
314
375
  "properties": {
315
- "hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hot)",
316
- "hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hotonly)",
317
- "lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-lazy-)",
318
- "bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-bonjour)",
319
- "publicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-publicpath-)",
320
- "host": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-host)",
321
- "allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-allowedhosts)",
322
- "logLevel": "should be {String} and equal to one of the allowed values\n\n [ 'trace', 'debug', 'info', 'warn', 'error', 'silent' ]\n\n(https://webpack.js.org/configuration/dev-server/#devserver-loglevel)",
323
- "filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)",
324
- "port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)",
325
- "socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)",
326
- "sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)",
327
- "watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)",
328
- "writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)",
329
- "headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)",
330
- "clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'trace', 'debug', 'info', 'warn', 'error', 'silent' ]\n\n(https://webpack.js.org/configuration/dev-server/#devserver-clientloglevel)",
331
- "overlay": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-overlay)",
332
- "progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-progress-cli-only)",
333
- "key": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-key)",
334
- "cert": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-cert)",
335
- "ca": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-ca)",
336
- "pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-pfx)",
337
- "pfxPassphrase": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-pfxpassphrase)",
338
- "requestCert": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-requestcert)",
339
- "inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-inline)",
340
- "disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck)",
341
- "public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-public)",
342
- "https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-https)",
343
- "http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-http2)",
344
- "contentBase": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-contentbase)",
345
- "watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-watchcontentbase)",
346
- "open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-open)",
347
- "useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-uselocalip)",
348
- "openPage": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-openpage)",
349
- "features": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-features)",
350
- "compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-compress)",
351
- "proxy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hot)",
352
- "historyApiFallback": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback)",
353
- "staticOptions": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-staticOptions)",
354
- "setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-setup)",
355
- "before": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-before)",
356
- "after": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-after)",
357
- "stats": "should be {Boolean|Object|String} (https://webpack.js.org/configuration/dev-server/#devserver-stats-)",
358
- "reporter": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-reporter)",
359
- "logTime": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-logtime)",
360
- "noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-noinfo-)",
376
+ "after": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverafter)",
377
+ "allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserverallowedhosts)",
378
+ "before": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverbefore)",
379
+ "bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)",
380
+ "ca": "should be {String|Buffer}",
381
+ "cert": "should be {String|Buffer}",
382
+ "clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
383
+ "compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
384
+ "contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
385
+ "disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
386
+ "features": "should be {Array}",
387
+ "filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserverfilename-)",
388
+ "fs": "should be {Object} (https://github.com/webpack/webpack-dev-middleware#fs)",
389
+ "headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverheaders-)",
390
+ "historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)",
391
+ "host": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserverhost)",
392
+ "hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
393
+ "hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhotonly)",
394
+ "http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttp2)",
395
+ "https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttps)",
396
+ "index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",
397
+ "injectClient": "should be {Boolean|Function}",
398
+ "injectHot": "should be {Boolean|Function}",
399
+ "inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverinline)",
400
+ "key": "should be {String|Buffer}",
401
+ "lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlazy-)",
402
+ "liveReload": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlivereload-)",
403
+ "log": "should be {Function}",
404
+ "logLevel": "should be {String} and equal to one of the allowed values\n\n [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]\n\n (https://github.com/webpack/webpack-dev-middleware#loglevel)",
405
+ "logTime": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#logtime)",
361
406
  "mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
362
- "quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-quiet-)",
363
- "serverSideRender": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-serversiderender)",
364
- "index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-index)",
365
- "log": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-log)",
366
- "warn": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-warn)"
407
+ "noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservernoinfo-)",
408
+ "onListening": "should be {Function} (https://webpack.js.org/configuration/dev-server/#onlistening)",
409
+ "open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserveropen)",
410
+ "openPage": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserveropenpage)",
411
+ "overlay": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserveroverlay)",
412
+ "pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserverpfx)",
413
+ "pfxPassphrase": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpfxpassphrase)",
414
+ "port": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserverport)",
415
+ "progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only)",
416
+ "proxy": "should be {Object|Array} (https://webpack.js.org/configuration/dev-server/#devserverproxy)",
417
+ "public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublic)",
418
+ "publicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublicpath-)",
419
+ "quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverquiet-)",
420
+ "reporter": "should be {Function} (https://github.com/webpack/webpack-dev-middleware#reporter)",
421
+ "requestCert": "should be {Boolean}",
422
+ "serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
423
+ "serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
424
+ "setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserversetup)",
425
+ "sockHost": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockhost)",
426
+ "sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversockpath)",
427
+ "sockPort": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockport)",
428
+ "socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)",
429
+ "staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)",
430
+ "stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats-)",
431
+ "useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserveruselocalip)",
432
+ "warn": "should be {Function}",
433
+ "watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverwatchcontentbase)",
434
+ "watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverwatchoptions-)",
435
+ "writeToDisk": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverwritetodisk-)"
367
436
  }
368
437
  },
369
438
  "additionalProperties": false
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ // base class that users should extend if they are making their own
4
+ // server implementation
5
+ module.exports = class BaseServer {
6
+ constructor(server) {
7
+ this.server = server;
8
+ }
9
+ };
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable
4
+ class-methods-use-this,
5
+ func-names
6
+ */
7
+ const sockjs = require('sockjs');
8
+ const BaseServer = require('./BaseServer');
9
+
10
+ // Workaround for sockjs@~0.3.19
11
+ // sockjs will remove Origin header, however Origin header is required for checking host.
12
+ // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
13
+ {
14
+ // eslint-disable-next-line global-require
15
+ const SockjsSession = require('sockjs/lib/transport').Session;
16
+ const decorateConnection = SockjsSession.prototype.decorateConnection;
17
+ SockjsSession.prototype.decorateConnection = function(req) {
18
+ decorateConnection.call(this, req);
19
+ const connection = this.connection;
20
+ if (
21
+ connection.headers &&
22
+ !('origin' in connection.headers) &&
23
+ 'origin' in req.headers
24
+ ) {
25
+ connection.headers.origin = req.headers.origin;
26
+ }
27
+ };
28
+ }
29
+
30
+ module.exports = class SockJSServer extends BaseServer {
31
+ // options has: error (function), debug (function), server (http/s server), path (string)
32
+ constructor(server) {
33
+ super(server);
34
+ this.socket = sockjs.createServer({
35
+ // Use provided up-to-date sockjs-client
36
+ sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js',
37
+ // Limit useless logs
38
+ log: (severity, line) => {
39
+ if (severity === 'error') {
40
+ this.server.log.error(line);
41
+ } else {
42
+ this.server.log.debug(line);
43
+ }
44
+ },
45
+ });
46
+
47
+ this.socket.installHandlers(this.server.listeningApp, {
48
+ prefix: this.server.sockPath,
49
+ });
50
+ }
51
+
52
+ send(connection, message) {
53
+ connection.write(message);
54
+ }
55
+
56
+ close(connection) {
57
+ connection.close();
58
+ }
59
+
60
+ // f should return the resulting connection
61
+ onConnection(f) {
62
+ this.socket.on('connection', f);
63
+ }
64
+ };