Skip to content

Commit 89ae007

Browse files
committed
feat: deprecate setup in favor of before and after hooks
fixes #869
1 parent 3e24ac4 commit 89ae007

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

examples/node-api-middleware/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const server = new WebpackDevServer(compiler, {
99
stats: {
1010
colors: true
1111
},
12-
setup(app) {
12+
before(app) {
1313
app.use((req, res, next) => {
1414
console.log(`Using middleware for ${req.url}`);
1515
next();

lib/Server.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,19 @@ function Server(compiler, options) {
321321
}
322322
},
323323

324+
before: () => {
325+
if (typeof options.before === 'function') { options.before(app, this); }
326+
},
327+
324328
middleware: () => {
325329
// include our middleware to ensure it is able to handle '/index.html' request after redirect
326330
app.use(this.middleware);
327331
},
328332

333+
after: () => {
334+
if (typeof options.after === 'function') { options.after(app, this); }
335+
},
336+
329337
headers: () => {
330338
app.all('*', this.setContentHeaders.bind(this));
331339
},
@@ -335,16 +343,18 @@ function Server(compiler, options) {
335343
},
336344

337345
setup: () => {
346+
log('Using "setup" is deprecated and will be removed in the next major version. Please use the "before" and "after" hooks instead.');
347+
log('If "setup" was working fine for you until now, simply replace it with "before"');
338348
if (typeof options.setup === 'function') { options.setup(app, this); }
339349
}
340350
};
341351

342-
const defaultFeatures = ['setup', 'headers', 'middleware'];
343-
if (options.proxy) { defaultFeatures.push('proxy', 'middleware'); }
352+
const defaultFeatures = ['before', 'setup', 'headers', 'middleware', 'after'];
353+
if (options.proxy) { defaultFeatures.push('proxy', 'middleware', 'after'); }
344354
if (contentBase !== false) { defaultFeatures.push('contentBaseFiles'); }
345355
if (options.watchContentBase) { defaultFeatures.push('watchContentBase'); }
346356
if (options.historyApiFallback) {
347-
defaultFeatures.push('historyApiFallback', 'middleware');
357+
defaultFeatures.push('historyApiFallback', 'middleware', 'after');
348358
if (contentBase !== false) { defaultFeatures.push('contentBaseFiles'); }
349359
}
350360
defaultFeatures.push('magicHtml');

lib/optionsSchema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@
274274
"description": "Exposes the Express server to add custom middleware or routes.",
275275
"instanceof": "Function"
276276
},
277+
"before": {
278+
"description": "Exposes the Express server to add custom middleware or routes before webpack-dev-middleware will be added.",
279+
"instanceof": "Function"
280+
},
281+
"after": {
282+
"description": "Exposes the Express server to add custom middleware or routes after webpack-dev-middleware got added.",
283+
"instanceof": "Function"
284+
},
277285
"stats": {
278286
"description": "Decides what bundle information is displayed.",
279287
"anyOf": [

test/Validation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Validation', () => {
5151
' object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, ' +
5252
'watchOptions?, headers?, clientLogLevel?, overlay?, progress?, key?, cert?, ca?, pfx?, pfxPassphrase?, requestCert?, ' +
5353
'inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, ' +
54-
'compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, ' +
54+
'compress?, proxy?, historyApiFallback?, staticOptions?, setup?, before?, after?, stats?, reporter?, ' +
5555
'noInfo?, quiet?, serverSideRender?, index?, log?, warn? }'
5656
]
5757
}];

0 commit comments

Comments
 (0)