Skip to content

Dockerfile for a simple Node.js server to relay messages to Socket.IO clients.

License

Notifications You must be signed in to change notification settings

dmhendricks/docker-socketio-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Author License DigitalOcean Twitter BrowserStack

Simple Message Relay Server

A simple Node.js message relay for Docker for transmitting to Socket.IO clients.

  1. Run the Docker service.
  2. Create a listener on the client, such as a web page.
  3. Send messages using cURL or your favorite REST client.

For more information, see my nodejs-simple-message-relay example and screenshot.

Deployment

Issue the following command to run in Docker:

docker run -p 3000:3000 --name socketio-relay -e API_KEY=MY_SECRET_API_KEY hendridm/socketio-relay

See Client Side Example Code or 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. 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, you could issue the following command:

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). In this way, you can set different listeners and send different messages to different sockets.

Analytics