You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide options to [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) which handles webpack assets.
4
+
5
+
**webpack.config.js**
6
+
7
+
```js
8
+
module.exports= {
9
+
// ...
10
+
devServer: {
11
+
devMiddleware: {
12
+
index:true,
13
+
headers: {
14
+
"X-Custom-Header":"yes",
15
+
},
16
+
},
17
+
},
18
+
};
19
+
```
20
+
21
+
To run this example use the following command:
22
+
23
+
```console
24
+
npx webpack serve --open
25
+
```
26
+
27
+
## What should happen
28
+
29
+
1. The script should open `http://localhost:8080/`.
30
+
2. You should see the text on the page itself change to read `Success!`.
31
+
3. Open the console in your browser's devtools and select the _Network_ tab.
32
+
4. Find `main.js`. The response headers should contain `X-Custom-Header: yes`.
33
+
34
+
Now update `webpack.config.js` with [`index: false`](https://github.com/webpack/webpack-dev-middleware#index), this will tell the server to not respond to requests to the root URL.
35
+
36
+
Now close and restart the server with:
37
+
38
+
```console
39
+
npx webpack serve --open
40
+
```
41
+
42
+
## What should happen
43
+
44
+
1. The script should open `http://localhost:8080/`.
45
+
2. You should see the `Cannot GET /` text on the page.
0 commit comments