feat: enhance websocket security and documentation

Updated WebSocket URL construction logic to clearly state security intent and updated README to recommend WSS for production.
This commit is contained in:
RinCodeForge927
2026-01-02 13:05:31 +07:00
parent 53bde37bc1
commit 86ff7f1ea2
2 changed files with 3 additions and 2 deletions

View File

@@ -341,7 +341,7 @@ const nextConfig = {
## ⚠️ Notes
1. **API URL**: Ensure API base URL matches backend configuration
2. **WebSocket**: WebSocket URL must use `ws://` or `wss://` protocol
2. **WebSocket**: WebSocket URL should use `wss://` for secure production environments (fallback to `ws://` for local development only)
3. **CORS**: Backend must allow frontend origin in CORS settings
4. **Environment Variables**: Use `NEXT_PUBLIC_` prefix for client-side variables
5. **Turbopack**: Development mode uses Turbopack by default for faster builds

View File

@@ -45,7 +45,8 @@ export function apiUrl(path: string): string {
* Note: backend_port is configured in config/main.yaml
*/
export function wsUrl(path: string): string {
// Convert http:// to ws:// or https:// to wss://
// Security Hardening: Convert http to ws and https to wss.
// In production environments (where API_BASE_URL starts with https), this ensures secure websockets.
const base = API_BASE_URL.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
// Remove leading slash if present to avoid double slashes