A dynamic HTTP reverse proxy with WebSocket support that allows runtime configuration management through a REST API.
- ✅ HTTP and WebSocket reverse proxy
- ✅ Runtime configuration management
- ✅ Host-based routing (virtual hosts)
- ✅ Wildcard pattern support (
*.example.com,api.*.com,**.subdomain.com) - ✅ Token-based authentication
- ✅ Auto-cleanup of stale routes
- ✅ Debug logging with colors
- ✅ Graceful shutdown
- ✅ RESTful API for route management
git clone https://github.com/sammwyy/HotRouter
cd hotrouter
go mod tidy
go build -o hotrouter# Start HotRouter with required secret token
./hotrouter --secret mySecretToken123
# Start with custom ports
./hotrouter --port 8000 --dashport 9000 --secret mySecretToken123
# Enable debug mode and custom auto-cleanup time
./hotrouter --secret mySecretToken123 --debug --autoclean 30m-p, --port: Port for the proxy server (default: 80)-d, --dashport: Port for the dashboard API (default: 8080)-s, --secret: Secret token for API authentication (required)--debug: Enable debug logging--autoclean: Auto-clean inactive routes after duration (default: 1h, use 0 to disable)
All API endpoints require authentication using Bearer token:
Authorization: Bearer <your-secret-token>Add or update a route configuration:
# Exact host match
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer mySecretToken123" \
-H "Content-Type: application/json" \
-d '{
"host": "api.example.com",
"target": "http://192.168.1.100:3000"
}'
# Wildcard patterns
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer mySecretToken123" \
-H "Content-Type: application/json" \
-d '{
"host": "*.example.com",
"target": "http://192.168.1.100:3000"
}'Retrieve all configured routes:
curl -X GET http://localhost:8080/routes \
-H "Authorization: Bearer mySecretToken123"Retrieve a specific route by host:
curl -X GET "http://localhost:8080/routes?host=api.example.com" \
-H "Authorization: Bearer mySecretToken123"Delete a route configuration:
curl -X DELETE "http://localhost:8080/routes?host=api.example.com" \
-H "Authorization: Bearer mySecretToken123"HotRouter supports flexible wildcard patterns for host matching:
Matches exactly one domain part:
*.example.com→ matchesapi.example.com,www.example.com, but NOTsub.api.example.comapi.*.com→ matchesapi.test.com,api.prod.com*.test.*→ matchesapi.test.com,www.test.org
Matches zero or more domain parts:
**.example.com→ matchesexample.com,api.example.com,sub.api.example.comapi.**.com→ matchesapi.com,api.test.com,api.test.prod.comserver1.**→ matchesserver1.test.local,server1.prod.example.com
# Match all subdomains of example.com
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "*.example.com", "target": "http://192.168.1.100:3000"}'
# Match any API subdomain
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "api.*.*", "target": "http://192.168.1.101:8000"}'
# Match any nested subdomain of test.local
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "**.test.local", "target": "http://192.168.1.102:4000"}'
# Match specific server with any domain structure
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "server1.**", "target": "http://192.168.1.103:5000"}'- Exact matches have highest priority
- Wildcard patterns are matched in the order they were added
- More specific patterns should be added before general ones
# Start HotRouter
./hotrouter --secret myToken --debug
# Configure route for a web app
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{
"host": "webapp.local",
"target": "http://127.0.0.1:3000"
}'
# Now requests to webapp.local will be proxied to 127.0.0.1:3000# Configure route for a WebSocket server
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{
"host": "chat.local",
"target": "http://127.0.0.1:4000"
}'
# WebSocket connections to ws://chat.local will be proxied to ws://127.0.0.1:4000# API service
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "api.myapp.com", "target": "http://192.168.1.10:8000"}'
# Frontend service
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "myapp.com", "target": "http://192.168.1.11:3000"}'
# Admin panel
curl -X POST http://localhost:8080/routes \
-H "Authorization: Bearer myToken" \
-H "Content-Type: application/json" \
-d '{"host": "admin.myapp.com", "target": "http://192.168.1.12:4000"}'Routes that haven't received requests for the specified duration will be automatically removed:
- Default: 1 hour
- Configurable via
--autocleanflag - Set to
0to disable auto-cleanup - Cleanup runs every half of the auto-cleanup interval
When enabled with --debug, you'll see detailed logs:
- Route additions/deletions
- Proxy requests (HTTP and WebSocket)
- Auto-cleanup operations
- Connection errors
HotRouter automatically detects WebSocket upgrade requests and handles the proxying of WebSocket connections transparently. No additional configuration is needed.
HotRouter handles SIGINT and SIGTERM signals gracefully:
- Stops accepting new connections
- Allows existing connections to complete
- Shuts down within 10 seconds maximum
{
"status": "success",
"message": "Route added"
}{
"host": "api.example.com",
"target": "http://192.168.1.100:3000",
"last_access": "2023-12-01T10:30:00Z"
}{
"error": "Route not found"
}MIT License