Skip to content

Commit 1e87e78

Browse files
authored
docs: add onAfterSetupMiddleware example (#3705)
1 parent 1c57680 commit 1e87e78

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# onAfterSetupMiddleware
2+
3+
Provides the ability to execute custom middleware after all other middleware internally within the server.
4+
5+
**webpack.config.js**
6+
7+
```js
8+
module.exports = {
9+
// ...
10+
devServer: {
11+
onAfterSetupMiddleware: (devServer) => {
12+
devServer.app.get("/after/some/path", (_, response) => {
13+
response.send("after");
14+
});
15+
},
16+
},
17+
};
18+
```
19+
20+
To run this example use the following command:
21+
22+
```console
23+
npx webpack serve --open
24+
```
25+
26+
## What Should Happen
27+
28+
1. The script should open `http://localhost:8080/` in your default browser.
29+
2. You should see the text on the page itself change to read `Success!`.
30+
3. Go to `http://localhost:8080/after/some/path`, you should see the text on the page itself change to read `after`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
const target = document.querySelector("#target");
4+
5+
target.classList.add("pass");
6+
target.innerHTML = "Success!";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
// our setup function adds behind-the-scenes bits to the config that all of our
4+
// examples need
5+
const { setup } = require("../util");
6+
7+
module.exports = setup({
8+
context: __dirname,
9+
entry: "./app.js",
10+
devServer: {
11+
onAfterSetupMiddleware: (devServer) => {
12+
devServer.app.get("/after/some/path", (_, response) => {
13+
response.send("after");
14+
});
15+
},
16+
},
17+
});

0 commit comments

Comments
 (0)