|
1 | | -# docker-socketio-relay |
2 | | -Dockerfile for a simple Node.js server to relay messages to Socket.IO clients |
| 1 | +[](https://www.danhendricks.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fdocker-socketio-relay) |
| 2 | +[](https://github.com/dmhendricks/docker-socketio-relay/blob/master/LICENSE) |
| 3 | +[](https://m.do.co/t/8a88362f5683?utm_source=github.com&utm_medium=campaign&utm_content=referral&utm_campaign=dmhendricks%2Fdocker-socketio-relay) |
| 4 | +[](https://twitter.com/danielhendricks) |
| 5 | +[](https://browserstack.com/?utm_source=github.com&utm_medium=referral&utm_content=link&utm_campaign=dmhendricks%2Fdocker-socketio-relay) |
| 6 | + |
| 7 | +# Simple Message Relay Server |
| 8 | + |
| 9 | +A simple [Node.js](https://nodejs.org/) message relay for Docker for transmitting to [Socket.IO](https://socket.io/) clients. |
| 10 | + |
| 11 | +1. Run the Docker service. |
| 12 | +2. Create a listener on the client, such as a [web page](https://github.com/dmhendricks/docker-socketio-relay/blob/master/demo.html). |
| 13 | +3. Send messages using cURL or your favorite REST client. |
| 14 | + |
| 15 | +For more information, see my [nodejs-simple-message-relay](https://github.com/dmhendricks/nodejs-simple-message-relay/) example and [screenshot](https://github.com/dmhendricks/nodejs-simple-message-relay/blob/master/README.md#screenshot). |
| 16 | + |
| 17 | +## Deployment |
| 18 | + |
| 19 | +Issue the following command to run in Docker: |
| 20 | + |
| 21 | +```bash |
| 22 | +docker run -p 3000:3000 --name socketio-relay -e API_KEY=MY_SECRET_API_KEY hendridm/socketio-relay |
| 23 | +``` |
| 24 | + |
| 25 | +:pushpin: See [demo.html](https://github.com/dmhendricks/docker-socketio-relay/blob/master/demo.html) for an example of using the Socket.IO browser client to receive messages. |
| 26 | + |
| 27 | +### Environmental Variables |
| 28 | + |
| 29 | +- `API_KEY` - The API key required to send messages to clients. |
| 30 | +- `DEBUG` - Add `-e DEBUG=1` to display incoming messages to the console. |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Once you have to service running and one or more clients connected, you can send messages to them using your favorite REST client. You can send any data you like as long as it's in JSON. For example, to send a message to the included [demo.html](https://github.com/dmhendricks/docker-socketio-relay/blob/master/demo.html), you could issue the following command: |
| 35 | + |
| 36 | +```bash |
| 37 | +curl --location --request POST 'http://localhost:3000/socket/my-socket-name?api_key=MY_SECRET_API_KEY' \ |
| 38 | + --header 'Content-Type: application/json' \ |
| 39 | + --data-raw '{ "message": "Hello World!" }' |
| 40 | +``` |
| 41 | + |
| 42 | +[](https://ga-beacon.appspot.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fdocker-socketio-relay) |
0 commit comments