Skip to content

Commit

Permalink
docs(configuration): add onListening, update after and before in devS…
Browse files Browse the repository at this point in the history
…erver (#3317)

* content-dev-server: add onListening and update after and before functions

* content-dev-server: updated onListening example and description
  • Loading branch information
billy-le authored and EugeneHlushko committed Oct 28, 2019
1 parent 0725c91 commit b14bd1d
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/content/configuration/dev-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ T> HTML template is required to serve the bundle, usually it is an `index.html`

## `devServer.after`

`function (app, server)`
`function (app, server, compiler)`

Provides the ability to execute custom middleware after all other middleware
internally within the server.
Expand All @@ -75,7 +75,7 @@ __webpack.config.js__
module.exports = {
//...
devServer: {
after: function(app, server) {
after: function(app, server, compiler) {
// do fancy stuff
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ webpack-dev-server --entry /entry/file --output-path /output/path --allowed-host

## `devServer.before`

`function (app, server)`
`function (app, server, compiler)`

Provides the ability to execute custom middleware prior to all other middleware
internally within the server. This could be used to define custom handlers, for
Expand All @@ -143,7 +143,7 @@ __webpack.config.js__
module.exports = {
//...
devServer: {
before: function(app, server) {
before: function(app, server, compiler) {
app.get('/some/path', function(req, res) {
res.json({ custom: 'response' });
});
Expand Down Expand Up @@ -763,6 +763,25 @@ module.exports = {
};
```

## `devServer.onListening`

`function (server)`

Provides an option to execute a custom function when `webpack-dev-server` starts listening for connections on a port.

__webpack.config.js__

```javascript
module.exports = {
//...
devServer: {
onListening: function(server) {
const port = server.listeningApp.address().port;
console.log('Listening on port:', port);
}
}
};
```

## `devServer.open`

Expand Down

0 comments on commit b14bd1d

Please sign in to comment.