0.0.8 • Published 1 year ago

websocket-test-server v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

{
	"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.

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.

0.0.8

1 year ago

0.0.5

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago