Skip to content

Commit

Permalink
Add more examples.
Browse files Browse the repository at this point in the history
Ref #581
  • Loading branch information
SpaceK33z committed Sep 3, 2016
1 parent 6d064d9 commit be21827
Show file tree
Hide file tree
Showing 34 changed files with 228 additions and 5 deletions.
15 changes: 15 additions & 0 deletions examples/cli-public/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https

NOTE: replace `<insert local ip>` with your local ip.

```shell
node ../../bin/webpack-dev-server.js --open --host 0.0.0.0 --public <insert local ip>:8080
```

If you want to make the client publicly accessible, the client needs to know with what host to connect to the server. If `--host 0.0.0.0` is given, the client would try to connect to `0.0.0.0`. With `--public` it is possible to override this.

## What should happen

The script should open `http://0.0.0.0:8080/`. In the app you should see "It's working."

Verify that the websocket is connecting to `<insert local ip>:8080`. Go to devtools -> Network, click on "websocket" and check "Request URL".
1 change: 1 addition & 0 deletions examples/cli-public/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/cli-public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: CLI public</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/cli-public/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
11 changes: 11 additions & 0 deletions examples/cli-stdin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https

```shell
node ../../bin/webpack-dev-server.js --stdin
```

When stdin ends, we want to close the webpack-dev-server.

## What should happen

The script should start up. When `ctrl+D` is pressed, the server should quit. Note that the shortcut can differ on operating systems, but the point is to signify the end of input.
1 change: 1 addition & 0 deletions examples/cli-stdin/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/cli-stdin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: CLI - stdin</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/cli-stdin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
13 changes: 13 additions & 0 deletions examples/compression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Compression

```shell
node ../../bin/webpack-dev-server.js --open --compress
```

Gzip compression is enabled.

## What should happen

The script should open `https://localhost:8080/`.

Open the devtools -> `Network` tab, and find `bundle.js`. The response headers should have a `Content-Encoding: gzip` header.
1 change: 1 addition & 0 deletions examples/compression/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/compression/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: compression</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/compression/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
15 changes: 15 additions & 0 deletions examples/history-api-fallback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# History API fallback

```shell
node ../../bin/webpack-dev-server.js --open --history-api-fallback
```

Enables support for history API fallback, which means that a request will fallback to `/index.html` if no resource can be found.

Note that by default, some URLs don't work. For example, if the url contains a dot. Be sure to checkout the [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback) options.

## What should happen

The script should open `http://localhost:8080/`, and you should see "It's working from path /".

Go to `http://localhost:8080/foo/bar`. You should see "It's working from path /foo/bar".
2 changes: 2 additions & 0 deletions examples/history-api-fallback/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var path = document.location.pathname;
document.write("It's working from path <b>" + path + "</b>");
9 changes: 9 additions & 0 deletions examples/history-api-fallback/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: history API fallback</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/history-api-fallback/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
13 changes: 13 additions & 0 deletions examples/host-port/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https

```shell
node ../../bin/webpack-dev-server.js --open --port 5000 --host 0.0.0.0
```

We want to change the port to `5000`, and make the server publicly accessible.

## What should happen

The script should open `http://0.0.0.0:5000/`. You should see "It's working."

Get your local ip (e.g. `192.168.1.40`), and try it from `192.168.1.40:5000`. Make sure your firewall doesn't block this port.
1 change: 1 addition & 0 deletions examples/host-port/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/host-port/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: host and port</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/host-port/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
2 changes: 1 addition & 1 deletion examples/modus-iframe/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: iframe</h1>
<h1>Example: modus - iframe</h1>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/modus-inline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: inline</h1>
<h1>Example: modus - inline</h1>
<br>
<img src="/svg.svg" style="width: 200px;">
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/modus-lazy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
node ../../bin/webpack-dev-server.js --open --lazy
```

With the `lazy` modus, webpack-dev-server does *not* watch the files, automatically recompiles them and refresh the browser. Instead, it only compiles after you manually refresh the page.
With the `lazy` modus, webpack-dev-server does **not** watch the files, automatically recompile them or refresh the browser. Instead, it only compiles after you manually refresh the page.

## What should happen

Expand Down
2 changes: 1 addition & 1 deletion examples/modus-lazy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: lazy</h1>
<h1>Example: modus - lazy</h1>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/modus-manual-script/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: manual script</h1>
<h1>Example: modus - manual script</h1>
</body>
</html>
15 changes: 15 additions & 0 deletions examples/proxy-advanced/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Proxy: simple

```shell
node ../../bin/webpack-dev-server.js --open
```

We want to proxy all urls that start with `/api` to `http://jsonplaceholder.typicode.com/`, but remove `/api` from the url. So `http://localhost:8080/api/users` should do a request to `http://jsonplaceholder.typicode.com/users`.

## What should happen

The script should open `http://localhost:8080/`. It should show "It's working."

Go to `http://localhost:8080/api/users`. It should show a couple of JSON objects.

Go to `http://localhost:8080/api/nope`. It should show the "Bypassed proxy!".
1 change: 1 addition & 0 deletions examples/proxy-advanced/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
8 changes: 8 additions & 0 deletions examples/proxy-advanced/bypass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<h1>Example: proxy advanced</h1>

Bypassed proxy!
</body>
</html>
9 changes: 9 additions & 0 deletions examples/proxy-advanced/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: proxy - advanced</h1>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/proxy-advanced/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
context: __dirname,
entry: "./app.js",
devServer: {
proxy: {
'/api': {
target: 'http://jsonplaceholder.typicode.com/',
changeOrigin: true,
pathRewrite: {
'^/api': ''
},
bypass: function(req) {
if (req.url === '/api/nope') {
return '/bypass.html';
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions examples/proxy-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Proxy: simple

```shell
node ../../bin/webpack-dev-server.js --open
```

In `webpack.config.js` there is a very simple configuration for a proxy. Note that this only works when proxying to a direct ip address. See the proxy-advanced example if you want to proxy to a domain.

## What should happen

The script should open `http://localhost:8080/`. It should show "It's working."

Browse to `http://localhost:8080/api/hey`. Since the proxy target does not actually exist, the CLI should give the error `[HPM] PROXY ERROR: ECONNREFUSED. localhost -> http://127.0.0.1:50545/api/hey`.
1 change: 1 addition & 0 deletions examples/proxy-simple/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/proxy-simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: proxy - simple</h1>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/proxy-simple/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
context: __dirname,
entry: "./app.js",
devServer: {
proxy: {
'/api': 'http://127.0.0.1:50545',
}
}
}

0 comments on commit be21827

Please sign in to comment.