Skip to content

Commit

Permalink
docs: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 15, 2021
1 parent ebb8339 commit 2a0b0a1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/headers/array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# headers option as an object

Adds headers to all responses.

**webpack.config.js**

```js
module.exports = {
// ...
devServer: {
headers: [
{
key: "X-Foo",
value: "value1",
},
{
key: "X-Bar",
value: "value2",
},
],
},
};
```

To run this example use the following command:

```console
npx webpack serve --open
```

## What should happen

1. The script should open `http://localhost:8080/`.
2. You should see the text on the page itself change to read `Success!`.
3. Open the console in your browser's devtools and select the _Network_ tab.
4. Find `main.js`. The response headers should contain `X-Foo: value1` and `X-Bar: value2`.
6 changes: 6 additions & 0 deletions examples/headers/array/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

const target = document.querySelector("#target");

target.classList.add("pass");
target.innerHTML = "Success!";
22 changes: 22 additions & 0 deletions examples/headers/array/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

// our setup function adds behind-the-scenes bits to the config that all of our
// examples need
const { setup } = require("../../util");

module.exports = setup({
context: __dirname,
entry: "./app.js",
devServer: {
headers: [
{
key: "X-Foo",
value: "value1",
},
{
key: "X-Bar",
value: "value2",
},
],
},
});

0 comments on commit 2a0b0a1

Please sign in to comment.