WebSocket proxy for post http requests. Perfect for testing purposes/mocks ๐
npm i -g wspr
Just run
wspr
after, you will see output with 2 urls:
WebSocket server started ws://localhost:3005
HTPP proxy server started http://localhost:3006
To broadcast a message to clients, send a POST request with a string/JSON body (via Postman or cURL) to the HTTP endpoint provided in the previous step.
curl -d "{"hello": "world"}" -X POST http://localhost:3006
If you want to run the websocket server over a secure connection, follow these steps:
-
create self signed certificates: https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates
-
trust the self signed certs, eg on mac: https://tosbourn.com/getting-os-x-to-trust-self-signed-ssl-certificates/
-
pass the paths to the certificate and key using the
--cert
and--key
CLI args, eg:
wspr --cert=./localhost.crt --key=./localhost.key
- you should see the websocket is now running over wss:
WebSocket server started wss://localhost:3005
Just specify --proxyWsUrl='wss://your.url/andPath'
and all the messages from your actual server will be proxied via WSPR with the ability for you to send any extra messages to your clients (useful during new feature implementation when the server has not implemented some messages yet).