Provide options to webpack-dev-middleware which handles webpack assets.
webpack.config.js
module.exports = {
// ...
devServer: {
devMiddleware: {
index: true,
headers: {
"X-Custom-Header": "yes",
},
},
},
};
To run this example use the following command:
npx webpack serve --open
- The script should open
http://localhost:8080/
. - You should see the text on the page itself change to read
Success!
. - Open the console in your browser's devtools and select the Network tab.
- Find
main.js
. The response headers should containX-Custom-Header: yes
.
Now update webpack.config.js
with index: false
, this will tell the server to not respond to requests to the root URL.
Now close and restart the server with:
npx webpack serve --open
- The script should open
http://localhost:8080/
. - You should see the
Cannot GET /
text on the page.