mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 06:09:40 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user