Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit 9fc3780

Browse files
jamesblightwmonk
authored andcommitted
Update docs with WebSocket proxy information (#2305)
* Update docs with WebSocket proxy information * Tweak wording
1 parent 2bd9c8b commit 9fc3780

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/react-scripts/template/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
4444
- [Proxying API Requests in Development](#proxying-api-requests-in-development)
4545
- ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy)
4646
- [Configuring the Proxy Manually](#configuring-the-proxy-manually)
47+
- [Configuring a WebSocket Proxy](#configuring-a-websocket-proxy)
4748
- [Using HTTPS in Development](#using-https-in-development)
4849
- [Generating Dynamic `<meta>` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
4950
- [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files)
@@ -992,6 +993,36 @@ You may also narrow down matches using `*` and/or `**`, to match the path exactl
992993
}
993994
```
994995

996+
### Configuring a WebSocket Proxy
997+
998+
When setting up a WebSocket proxy, there are a some extra considerations to be aware of.
999+
1000+
If you’re using a WebSocket engine like [Socket.io](https://socket.io/), you must have a Socket.io server running that you can use as the proxy target. Socket.io will not work with a standard WebSocket server. Specifically, don't expect Socket.io to work with [the websocket.org echo test](http://websocket.org/echo.html).
1001+
1002+
There’s some good documentation available for [setting up a Socket.io server](https://socket.io/docs/).
1003+
1004+
Standard WebSockets **will** work with a standard WebSocket server as well as the websocket.org echo test. You can use libraries like [ws](https://github.com/websockets/ws) for the server, with [native WebSockets in the browser](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
1005+
1006+
Either way, you can proxy WebSocket requests manually in `package.json`:
1007+
1008+
```js
1009+
{
1010+
// ...
1011+
"proxy": {
1012+
"/socket": {
1013+
// Your compatible WebSocket server
1014+
"target": "ws://<socket_url>",
1015+
// Tell http-proxy-middleware that this is a WebSocket proxy.
1016+
// Also allows you to proxy WebSocket requests without an additional HTTP request
1017+
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
1018+
"ws": true
1019+
// ...
1020+
}
1021+
}
1022+
// ...
1023+
}
1024+
```
1025+
9951026
## Using HTTPS in Development
9961027

9971028
>Note: this feature is available with `react-scripts@0.4.0` and higher.

0 commit comments

Comments
 (0)