@@ -39,43 +39,43 @@ function Server(compiler, options) {
39
39
this . contentBaseWatchers = [ ] ;
40
40
41
41
// Listening for events
42
- const invalidPlugin = function ( ) {
42
+ const invalidPlugin = ( ) => {
43
43
this . sockWrite ( this . sockets , "invalid" ) ;
44
- } . bind ( this ) ;
44
+ } ;
45
45
compiler . plugin ( "compile" , invalidPlugin ) ;
46
46
compiler . plugin ( "invalid" , invalidPlugin ) ;
47
- compiler . plugin ( "done" , function ( stats ) {
47
+ compiler . plugin ( "done" , ( stats ) => {
48
48
this . _sendStats ( this . sockets , stats . toJson ( clientStats ) ) ;
49
49
this . _stats = stats ;
50
- } . bind ( this ) ) ;
50
+ } ) ;
51
51
52
52
// Init express server
53
53
const app = this . app = new express ( ) ;
54
54
55
55
// middleware for serving webpack bundle
56
56
this . middleware = webpackDevMiddleware ( compiler , options ) ;
57
57
58
- app . get ( "/__webpack_dev_server__/live.bundle.js" , function ( req , res ) {
58
+ app . get ( "/__webpack_dev_server__/live.bundle.js" , ( req , res ) => {
59
59
res . setHeader ( "Content-Type" , "application/javascript" ) ;
60
60
fs . createReadStream ( path . join ( __dirname , ".." , "client" , "live.bundle.js" ) ) . pipe ( res ) ;
61
61
} ) ;
62
62
63
- app . get ( "/__webpack_dev_server__/sockjs.bundle.js" , function ( req , res ) {
63
+ app . get ( "/__webpack_dev_server__/sockjs.bundle.js" , ( req , res ) => {
64
64
res . setHeader ( "Content-Type" , "application/javascript" ) ;
65
65
fs . createReadStream ( path . join ( __dirname , ".." , "client" , "sockjs.bundle.js" ) ) . pipe ( res ) ;
66
66
} ) ;
67
67
68
- app . get ( "/webpack-dev-server.js" , function ( req , res ) {
68
+ app . get ( "/webpack-dev-server.js" , ( req , res ) => {
69
69
res . setHeader ( "Content-Type" , "application/javascript" ) ;
70
70
fs . createReadStream ( path . join ( __dirname , ".." , "client" , "index.bundle.js" ) ) . pipe ( res ) ;
71
71
} ) ;
72
72
73
- app . get ( "/webpack-dev-server/*" , function ( req , res ) {
73
+ app . get ( "/webpack-dev-server/*" , ( req , res ) => {
74
74
res . setHeader ( "Content-Type" , "text/html" ) ;
75
75
fs . createReadStream ( path . join ( __dirname , ".." , "client" , "live.html" ) ) . pipe ( res ) ;
76
76
} ) ;
77
77
78
- app . get ( "/webpack-dev-server" , function ( req , res ) {
78
+ app . get ( "/webpack-dev-server" , ( req , res ) => {
79
79
res . setHeader ( "Content-Type" , "text/html" ) ;
80
80
/* eslint-disable quotes */
81
81
res . write ( '<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>' ) ;
@@ -118,7 +118,7 @@ function Server(compiler, options) {
118
118
/* eslint-enable quotes */
119
119
writeDirectory ( options . publicPath || "/" , path ) ;
120
120
res . end ( "</body></html>" ) ;
121
- } . bind ( this ) ) ;
121
+ } ) ;
122
122
123
123
let contentBase ;
124
124
if ( options . contentBase !== undefined ) {
@@ -128,14 +128,14 @@ function Server(compiler, options) {
128
128
}
129
129
130
130
const features = {
131
- compress : function ( ) {
131
+ compress ( ) {
132
132
if ( options . compress ) {
133
133
// Enable gzip compression.
134
134
app . use ( compress ( ) ) ;
135
135
}
136
136
} ,
137
137
138
- proxy : function ( ) {
138
+ proxy ( ) {
139
139
if ( options . proxy ) {
140
140
/**
141
141
* Assume a proxy configuration specified as:
@@ -148,7 +148,7 @@ function Server(compiler, options) {
148
148
* }
149
149
*/
150
150
if ( ! Array . isArray ( options . proxy ) ) {
151
- options . proxy = Object . keys ( options . proxy ) . map ( function ( context ) {
151
+ options . proxy = Object . keys ( options . proxy ) . map ( ( context ) => {
152
152
let proxyOptions ;
153
153
// For backwards compatibility reasons.
154
154
const correctedContext = context . replace ( / ^ \* $ / , "**" ) . replace ( / \/ \* $ / , "" ) ;
@@ -168,7 +168,7 @@ function Server(compiler, options) {
168
168
} ) ;
169
169
}
170
170
171
- const getProxyMiddleware = function ( proxyConfig ) {
171
+ const getProxyMiddleware = ( proxyConfig ) => {
172
172
const context = proxyConfig . context || proxyConfig . path ;
173
173
174
174
// It is possible to use the `bypass` method without a `target`.
@@ -194,7 +194,7 @@ function Server(compiler, options) {
194
194
* }
195
195
* ]
196
196
*/
197
- options . proxy . forEach ( function ( proxyConfigOrCallback ) {
197
+ options . proxy . forEach ( ( proxyConfigOrCallback ) => {
198
198
let proxyConfig ;
199
199
let proxyMiddleware ;
200
200
@@ -206,7 +206,7 @@ function Server(compiler, options) {
206
206
207
207
proxyMiddleware = getProxyMiddleware ( proxyConfig ) ;
208
208
209
- app . use ( function ( req , res , next ) {
209
+ app . use ( ( req , res , next ) => {
210
210
if ( typeof proxyConfigOrCallback === "function" ) {
211
211
const newProxyConfig = proxyConfigOrCallback ( ) ;
212
212
if ( newProxyConfig !== proxyConfig ) {
@@ -230,7 +230,7 @@ function Server(compiler, options) {
230
230
}
231
231
} ,
232
232
233
- historyApiFallback : function ( ) {
233
+ historyApiFallback ( ) {
234
234
if ( options . historyApiFallback ) {
235
235
// Fall back to /index.html if nothing else matches.
236
236
app . use (
@@ -239,16 +239,16 @@ function Server(compiler, options) {
239
239
}
240
240
} ,
241
241
242
- contentBaseFiles : function ( ) {
242
+ contentBaseFiles ( ) {
243
243
if ( Array . isArray ( contentBase ) ) {
244
- contentBase . forEach ( function ( item ) {
244
+ contentBase . forEach ( ( item ) => {
245
245
app . get ( "*" , express . static ( item ) ) ;
246
246
} ) ;
247
247
} else if ( / ^ ( h t t p s ? : ) ? \/ \/ / . test ( contentBase ) ) {
248
248
console . log ( "Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead." ) ;
249
249
console . log ( 'proxy: {\n\t"*": "<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
250
250
// Redirect every request to contentBase
251
- app . get ( "*" , function ( req , res ) {
251
+ app . get ( "*" , ( req , res ) => {
252
252
res . writeHead ( 302 , {
253
253
"Location" : contentBase + req . path + ( req . _parsedUrl . search || "" )
254
254
} ) ;
@@ -258,7 +258,7 @@ function Server(compiler, options) {
258
258
console . log ( "Using a number as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead." ) ;
259
259
console . log ( 'proxy: {\n\t"*": "//localhost:<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
260
260
// Redirect every request to the port contentBase
261
- app . get ( "*" , function ( req , res ) {
261
+ app . get ( "*" , ( req , res ) => {
262
262
res . writeHead ( 302 , {
263
263
"Location" : `//localhost:${ contentBase } ${ req . path } ${ req . _parsedUrl . search || "" } `
264
264
} ) ;
@@ -270,45 +270,45 @@ function Server(compiler, options) {
270
270
}
271
271
} ,
272
272
273
- contentBaseIndex : function ( ) {
273
+ contentBaseIndex ( ) {
274
274
if ( Array . isArray ( contentBase ) ) {
275
- contentBase . forEach ( function ( item ) {
275
+ contentBase . forEach ( ( item ) => {
276
276
app . get ( "*" , serveIndex ( item ) ) ;
277
277
} ) ;
278
278
} else if ( ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( contentBase ) && typeof contentBase !== "number" ) {
279
279
app . get ( "*" , serveIndex ( contentBase ) ) ;
280
280
}
281
281
} ,
282
282
283
- watchContentBase : function ( ) {
283
+ watchContentBase : ( ) => {
284
284
if ( / ^ ( h t t p s ? : ) ? \/ \/ / . test ( contentBase ) || typeof contentBase === "number" ) {
285
285
throw new Error ( "Watching remote files is not supported." ) ;
286
286
} else if ( Array . isArray ( contentBase ) ) {
287
- contentBase . forEach ( function ( item ) {
287
+ contentBase . forEach ( ( item ) => {
288
288
this . _watch ( item ) ;
289
- } . bind ( this ) ) ;
289
+ } ) ;
290
290
} else {
291
291
this . _watch ( contentBase ) ;
292
292
}
293
- } . bind ( this ) ,
293
+ } ,
294
294
295
- middleware : function ( ) {
295
+ middleware : ( ) => {
296
296
// include our middleware to ensure it is able to handle '/index.html' request after redirect
297
297
app . use ( this . middleware ) ;
298
- } . bind ( this ) ,
298
+ } ,
299
299
300
- headers : function ( ) {
300
+ headers : ( ) => {
301
301
app . all ( "*" , this . setContentHeaders . bind ( this ) ) ;
302
- } . bind ( this ) ,
302
+ } ,
303
303
304
- magicHtml : function ( ) {
304
+ magicHtml : ( ) => {
305
305
app . get ( "*" , this . serveMagicHtml . bind ( this ) ) ;
306
- } . bind ( this ) ,
306
+ } ,
307
307
308
- setup : function ( ) {
308
+ setup : ( ) => {
309
309
if ( typeof options . setup === "function" )
310
310
options . setup ( app , this ) ;
311
- } . bind ( this )
311
+ }
312
312
} ;
313
313
314
314
const defaultFeatures = [ "setup" , "headers" , "middleware" ] ;
@@ -330,9 +330,9 @@ function Server(compiler, options) {
330
330
if ( options . compress )
331
331
defaultFeatures . unshift ( "compress" ) ;
332
332
333
- ( options . features || defaultFeatures ) . forEach ( function ( feature ) {
333
+ ( options . features || defaultFeatures ) . forEach ( ( feature ) => {
334
334
features [ feature ] ( ) ;
335
- } , this ) ;
335
+ } ) ;
336
336
337
337
if ( options . https ) {
338
338
// for keep supporting CLI parameters
@@ -390,16 +390,16 @@ Server.prototype.listen = function() {
390
390
}
391
391
}
392
392
} ) ;
393
- sockServer . on ( "connection" , function ( conn ) {
393
+ sockServer . on ( "connection" , ( conn ) => {
394
394
if ( ! conn ) return ;
395
395
this . sockets . push ( conn ) ;
396
396
397
- conn . on ( "close" , function ( ) {
397
+ conn . on ( "close" , ( ) => {
398
398
const connIndex = this . sockets . indexOf ( conn ) ;
399
399
if ( connIndex >= 0 ) {
400
400
this . sockets . splice ( connIndex , 1 ) ;
401
401
}
402
- } . bind ( this ) ) ;
402
+ } ) ;
403
403
404
404
if ( this . clientLogLevel )
405
405
this . sockWrite ( [ conn ] , "log-level" , this . clientLogLevel ) ;
@@ -411,7 +411,7 @@ Server.prototype.listen = function() {
411
411
412
412
if ( ! this . _stats ) return ;
413
413
this . _sendStats ( [ conn ] , this . _stats . toJson ( clientStats ) , true ) ;
414
- } . bind ( this ) ) ;
414
+ } ) ;
415
415
416
416
sockServer . installHandlers ( this . listeningApp , {
417
417
prefix : "/sockjs-node"
@@ -420,22 +420,22 @@ Server.prototype.listen = function() {
420
420
}
421
421
422
422
Server . prototype . close = function ( callback ) {
423
- this . sockets . forEach ( function ( sock ) {
423
+ this . sockets . forEach ( ( sock ) => {
424
424
sock . close ( ) ;
425
425
} ) ;
426
426
this . sockets = [ ] ;
427
- this . listeningApp . close ( function ( ) {
427
+ this . listeningApp . close ( ( ) => {
428
428
this . middleware . close ( callback ) ;
429
- } . bind ( this ) ) ;
429
+ } ) ;
430
430
431
- this . contentBaseWatchers . forEach ( function ( watcher ) {
431
+ this . contentBaseWatchers . forEach ( ( watcher ) => {
432
432
watcher . close ( ) ;
433
433
} ) ;
434
434
this . contentBaseWatchers = [ ] ;
435
435
}
436
436
437
437
Server . prototype . sockWrite = function ( sockets , type , data ) {
438
- sockets . forEach ( function ( sock ) {
438
+ sockets . forEach ( ( sock ) => {
439
439
sock . write ( JSON . stringify ( {
440
440
type : type ,
441
441
data : data
@@ -467,9 +467,7 @@ Server.prototype._sendStats = function(sockets, stats, force) {
467
467
stats &&
468
468
( ! stats . errors || stats . errors . length === 0 ) &&
469
469
stats . assets &&
470
- stats . assets . every ( function ( asset ) {
471
- return ! asset . emitted ;
472
- } )
470
+ stats . assets . every ( ( asset ) => ! asset . emitted )
473
471
)
474
472
return this . sockWrite ( sockets , "still-ok" ) ;
475
473
this . sockWrite ( sockets , "hash" , stats . hash ) ;
@@ -482,9 +480,9 @@ Server.prototype._sendStats = function(sockets, stats, force) {
482
480
}
483
481
484
482
Server . prototype . _watch = function ( path ) {
485
- const watcher = chokidar . watch ( path ) . on ( "change" , function ( ) {
483
+ const watcher = chokidar . watch ( path ) . on ( "change" , ( ) => {
486
484
this . sockWrite ( this . sockets , "content-changed" ) ;
487
- } . bind ( this ) )
485
+ } ) ;
488
486
489
487
this . contentBaseWatchers . push ( watcher ) ;
490
488
}
0 commit comments