Skip to content

docs(configuration): add devServer.setupMiddlewares option #5807

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 3 commits into from
Dec 22, 2021
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
42 changes: 42 additions & 0 deletions src/content/configuration/dev-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,48 @@ module.exports = {
};
```

## devServer.setupMiddlewares

`function (middlewares, devServer)`

<Badge text="v4.7.0+" />

Provides the ability to execute a custom function and apply custom middleware(s).

**webpack.config.js**

```javascript
module.exports = {
// ...
devServer: {
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}

devServer.app.get('/setup-middleware/some/path', (_, response) => {
response.send('setup-middlewares option GET');
});

middlewares.push({
name: 'hello-world-test-one',
// `path` is optional
path: '/foo/bar',
middleware: (req, res) => {
res.send('Foo Bar!');
},
});

middlewares.push((req, res) => {
res.send('Hello World!');
});

return middlewares;
},
},
};
```

## devServer.static

`boolean` `string` `[string]` `object` `[object]`
Expand Down