fix(ws): infer GATEWAY_WS_ORIGIN from CORS_ORIGIN if not set#455
Merged
Conversation
Previously defaulted to http://localhost:3000 which is rejected by the OpenClaw gateway when miso-chat is deployed behind a reverse proxy with a different allowed origin. Now checks CORS_ORIGIN (or ALLOWED_ORIGINS) as a fallback before falling back to localhost:3000, so deployments with CORS_ORIGIN set don't need to also set GATEWAY_WS_ORIGIN explicitly.
Contributor
|
✅ Automated recommendation: APPROVE Analysis engine: MiniMax-M2.7@https://api.minimax.io/v1 SummaryApprove. This PR fixes a deployment configuration issue where Change AnalysisBefore (line 889): const gatewayWsOrigin = process.env.GATEWAY_WS_ORIGIN || 'http://localhost:3000';After: // Infer GATEWAY_WS_ORIGIN from CORS_ORIGIN if not explicitly set
const configuredGatewayWsOrigin = process.env.GATEWAY_WS_ORIGIN;
const corsOrigin = process.env.CORS_ORIGIN || process.env.ALLOWED_ORIGINS || '';
const firstCorsOrigin = corsOrigin.split(',')[0].trim();
const gatewayWsOrigin = configuredGatewayWsOrigin || firstCorsOrigin || 'http://localhost:3000';Key Points
Standards Compliance
Unknowns / Needs Verification
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GATEWAY_WS_ORIGINpreviously defaulted tohttp://localhost:3000. When miso-chat is deployed behind a reverse proxy with a different external URL (e.g.https://miso-chat.jory.dev), the gateway rejects the WebSocket connection with "origin not allowed" becauselocalhost:3000isn't in its allowed origins list.Fix
Instead of hardcoding
localhost:3000, the code now checksCORS_ORIGIN(orALLOWED_ORIGINS) as a fallback before falling back tolocalhost:3000:This means deployments that already set
CORS_ORIGINdon't need to also setGATEWAY_WS_ORIGINexplicitly.Explicit
GATEWAY_WS_ORIGINstill takes precedence if set (for cases where WS origin needs to differ from CORS origin).