Skip to content

devserver: add before, after hook info #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/content/configuration/dev-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ W> Be aware that when [exporting multiple configurations](/configuration/configu

T> If you're having trouble, navigating to the `/webpack-dev-server` route will show where files are served. For example, `http://localhost:9000/webpack-dev-server`.

## `devServer.after`

`function`

Provides the ability to execute custom middleware after all other middleware
internally within the server.

```js
after(app){
// do fancy stuff
}
```

## `devServer.allowedHosts`

Expand Down Expand Up @@ -80,6 +92,21 @@ To use this option with the CLI pass the `--allowed-hosts` option a comma-delimi
webpack-dev-server --entry /entry/file --output-path /output/path --allowed-hosts .host.com,host2.com
```

## `devServer.before`

`function`

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
example:

```js
before(app){
app.get('/some/path', function(req, res) {
res.json({ custom: 'response' });
});
}
```

## `devServer.bonjour`

Expand Down Expand Up @@ -666,6 +693,8 @@ webpack-dev-server --quiet

`function`

W> This option is __deprecated__ in favor of `before` and will be removed in v3.0.0.

Here you can access the Express app object and add your own custom middleware to it.
For example, to define custom handlers for some paths:

Expand Down