https://github.com/dmhendricks/docker-socketio-relay
Dockerfile for a simple Node.js server to relay messages to Socket.IO clients.
https://github.com/dmhendricks/docker-socketio-relay
browser-notifications docker-image nodejs-server socket-io socket-io-client socketio-messaging socketio-server websockets
Last synced: 2 months ago
JSON representation
Dockerfile for a simple Node.js server to relay messages to Socket.IO clients.
- Host: GitHub
- URL: https://github.com/dmhendricks/docker-socketio-relay
- Owner: dmhendricks
- License: apache-2.0
- Created: 2020-02-02T01:29:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-02T03:15:32.000Z (about 5 years ago)
- Last Synced: 2025-02-15T12:56:34.470Z (2 months ago)
- Topics: browser-notifications, docker-image, nodejs-server, socket-io, socket-io-client, socketio-messaging, socketio-server, websockets
- Language: HTML
- Homepage: https://hub.docker.com/r/hendridm/socketio-relay
- Size: 19.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.danhendricks.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fdocker-socketio-relay)
[](https://github.com/dmhendricks/docker-socketio-relay/blob/master/LICENSE)
[](https://m.do.co/t/8a88362f5683?utm_source=github.com&utm_medium=campaign&utm_content=referral&utm_campaign=dmhendricks%2Fdocker-socketio-relay)
[](https://twitter.com/danielhendricks)
[](https://browserstack.com/?utm_source=github.com&utm_medium=referral&utm_content=link&utm_campaign=dmhendricks%2Fdocker-socketio-relay)# Simple Message Relay Server
A simple [Node.js](https://nodejs.org/) message relay for Docker for transmitting to [Socket.IO](https://socket.io/) clients.
1. Run the Docker service.
2. Create a listener on the client, such as a [web page](https://github.com/dmhendricks/docker-socketio-relay/blob/master/demo.html).
3. Send messages using cURL or your favorite REST client.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).
## Deployment
Issue the following command to run in Docker:
```bash
docker run -p 3000:3000 --name socketio-relay -e API_KEY=MY_SECRET_API_KEY hendridm/socketio-relay
```See [Client Side Example Code](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Client-Side-Example-Code) or [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.
### Environmental Variables
- `API_KEY` - The API key required to send messages to clients.
- `DEBUG` - Add `-e DEBUG=1` to display incoming messages to the console.## Usage
Once you have to service running and one or more clients connected, you can send messages to them using [your favorite REST client](https://www.getpostman.com/?utm_source=github.com&utm_medium=campaign&utm_content=referral&utm_campaign=dmhendricks%2Fdocker-socketio-relay). 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:
```bash
curl --location --request POST 'http://localhost:3000/socket/my-socket-name?api_key=MY_SECRET_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{ "message": "Hello World!" }'
```Note that "my-socket-name" in the endpoint above must match the name of the socket that you are listening to in the client (see [demo.html](https://github.com/dmhendricks/docker-socketio-relay/blob/master/demo.html)). In this way, you can set different listeners and send different messages to different sockets.
[](https://ga-beacon.appspot.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fdocker-socketio-relay)