https://github.com/truewinter/websocket-test-server
https://github.com/truewinter/websocket-test-server
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/truewinter/websocket-test-server
- Owner: TrueWinter
- License: mit
- Created: 2022-12-11T01:24:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-28T01:30:54.000Z (over 3 years ago)
- Last Synced: 2025-03-10T11:03:11.254Z (over 1 year ago)
- Language: JavaScript
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# WebSocket-Test-Server
Ever needed to test WebSockets on a website and wish you could send arbitrary data to the client without needing to rewrite the backend? Or maybe you're testing an integration with a 3rd-party WebSocket server but don't want to actually connect to their server during development? WebSocket-Test-Server can help.
## Installation
```
npm install --global websocket-test-server
```
## Usage
To use WebSocket-Test-Server, create a config file and then run `websocket-test-server` from the command line. The path to the config file must be absolute.
```json
{
"ws": {
"routes": [
"/eventsub"
],
"customRouteHandler": ""
},
"dashboard": {
"port": 8080
}
}
```
```
websocket-test-server --config /path/to/config.json
```
## Advanced Usage
The routes registered in the config file cannot be automated using code. All data sent to the clients must be done manually though the dashboard.
You can register routes programatically by setting the `customRouteHandler` config option to the path of a file using the WebSocket-Test-Server API. The path can be either relative to the directory containing the config file, or absolute.
```js
module.exports = (api) => {
api.registerRoute('/echo', (ws) => {
ws.on('message', (data) => {
let d = data.toString();
ws.send(d);
});
});
};
```
See the file(s) in the `api-example` directory for more information.