A simple web application for interacting with NATS messaging systems using the official NATS.ws client. This application allows you to:
- 🔌 Connect to a NATS server using WebSocket (WSS)
- 📂 Create topics
- 📤 Publish messages to topics
- 📥 Subscribe to topics and receive messages in real-time
- ✅ Official NATS.ws Client: Uses the official NATS WebSocket client for reliable connections
- 🔗 Connection Management: Connect to any NATS server that supports WebSocket connections
- 🔐 Authentication Support: Connect using username/password or token authentication
- 📂 Topic Creation: Create new topics on the NATS server
- 📤 Message Publishing: Send messages to any topic
- 📥 Topic Subscription: Subscribe to topics and view messages in real-time
- 📱 Responsive Design: Works on desktop and mobile devices
Since this is a browser-based application, your NATS server must be configured to support WebSocket connections:
- WebSocket URLs: Always use URLs that start with
ws://
orwss://
(secure) - Server Configuration: Your NATS server must be configured to accept WebSocket connections
- WebSocket Port: The WebSocket port is often different from the standard NATS port (4222)
- Common Ports: WebSocket connections typically use port 8080 (ws://) or 8443 (wss://)
- Authentication: For authenticated connections, use the separate authentication fields:
- Username & Password option with dedicated input fields
- Token authentication with dedicated token field
📝 Important Update: Embedding credentials in the URL (
wss://username:password@nats.example.com
) is no longer supported as it doesn't see to work reliably with the NATS.ws client. Always use the separate authentication fields.
To use this client, your NATS server must be configured to support WebSocket connections. Here's how to enable WebSocket support in your NATS server:
Add the following to your NATS server configuration file:
websocket {
port: 8080
no_tls: true
}
# For secure WebSocket (wss://)
websocket {
port: 8443
tls {
cert_file: "/path/to/cert.pem"
key_file: "/path/to/key.pem"
}
}
docker run -p 4222:4222 -p 8080:8080 nats:latest -js -m 8222 --websocket_port 8080
- Clone the repository
- Install dependencies:
npm install
- Start the development server:
npm run dev
- Open your browser and navigate to
http://localhost:5173
- Build the application:
npm run build
- The built files will be in the
dist
directory, ready to be deployed to any static hosting service like Cloudflare Pages.
- Push your code to a Git repository (GitHub, GitLab, etc.)
- Log in to your Cloudflare account and go to the Pages section
- Create a new project and connect it to your Git repository
- Configure the build settings:
- Build command:
npm run build
- Build output directory:
dist
- Build command:
- Deploy the site
-
Connect to NATS:
- Enter the WebSocket URL of your NATS server (e.g.,
wss://sandbox.nats.io:8443
) - Select your authentication method:
- No Authentication
- Username & Password: Enter your NATS username and password
- Token: Enter your NATS authentication token
- Enter the WebSocket URL of your NATS server (e.g.,
-
Create a Topic:
- Enter a topic name and click "Create Topic"
-
Publish Messages:
- Enter a topic name
- Type your message
- Click "Publish Message"
-
Subscribe to Topics:
- Enter a topic name
- Click "Subscribe"
- Messages will appear in the "Received Messages" section
The application includes several advanced features to help with troubleshooting:
- Connection Timeout: Adjust the connection timeout for slow networks
- Direct WebSocket Testing: Test basic WebSocket connectivity separate from the NATS protocol
- Advanced Options: Toggle additional connection options and debugging tools
- Server Configuration Examples: View examples of how to configure your NATS server for WebSocket support
If you encounter connection issues:
Solutions:
- Ensure your NATS server is running and accessible
- Verify the server URL and port are correct
- Check if your server has WebSocket support enabled
- Check for firewall or network restrictions
Solutions:
- Verify your credentials or token are correct
- Make sure you're using the correct authentication method for your server
- Check your NATS server's authentication configuration
Solutions:
- For
wss://
connections, ensure your server has a valid SSL certificate - If using a self-signed certificate, your browser may block the connection
- Try using
ws://
for local testing (not secure for production)
This application uses the official NATS.ws client for browser-based WebSocket connections to NATS servers. The NATS.ws client is maintained by the NATS team and provides reliable WebSocket connectivity.
- ⚛️ React
- 📝 TypeScript
- 🎨 Tailwind CSS
- 📡 NATS.ws (Official NATS WebSocket client)
- ⚡ Vite
MIT