Conversation
WalkthroughServer now injects a configurable Changes
sequenceDiagram
participant Server
participant Browser
participant ClientCode
participant WebSocketServer
Server->>Browser: Render HTML with `wsUrl` injected (window.WS_URL)
Browser->>ClientCode: Load scripts (window.WS_URL available)
ClientCode->>ClientCode: Read `window.WS_URL`, select ws/wss protocol
ClientCode->>WebSocketServer: Open WebSocket to protocol://window.WS_URL/...
WebSocketServer-->>ClientCode: Connection established / messages
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/server/RenderHtml.ts`:
- Line 29: The wsUrl build in RenderHtml.ts uses SUBDOMAIN and DOMAIN without
validation; update the wsUrl assignment (the wsUrl property construction) to use
safe fallbacks like SUBDOMAIN ?? "undefined" and DOMAIN ?? "undefined" (or a
sensible default) before JSON.stringify so clients don't get
"undefined.domain.com"; ensure you reference process.env.SUBDOMAIN and
process.env.DOMAIN and apply the same fallback pattern used for GIT_COMMIT and
GAME_ENV.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5a21cf52-0396-4774-b309-2d514c924c07
📒 Files selected for processing (5)
index.htmlsrc/client/Main.tssrc/client/Transport.tssrc/server/RenderHtml.tsvite.config.ts
| backgroundImageUrl: buildAssetUrl("images/background.webp", assetManifest), | ||
| desktopLogoImageUrl: buildAssetUrl("images/OpenFront.webp", assetManifest), | ||
| mobileLogoImageUrl: buildAssetUrl("images/OF.webp", assetManifest), | ||
| wsUrl: JSON.stringify(`${process.env.SUBDOMAIN}.${process.env.DOMAIN}`), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if SUBDOMAIN and DOMAIN are used elsewhere and how they're validated
echo "=== Searching for SUBDOMAIN and DOMAIN env var usage ==="
rg -n "process\.env\.(SUBDOMAIN|DOMAIN)" --type ts
echo ""
echo "=== Checking for existing env validation patterns ==="
rg -n "process\.env\.\w+.*\?\?" --type ts -A1 -B1 | head -40Repository: openfrontio/OpenFrontIO
Length of output: 1543
🏁 Script executed:
# Check build config, env setup, and how wsUrl is used
echo "=== Looking for build/deploy config ==="
find . -maxdepth 2 -type f \( -name "*.env*" -o -name ".env*" -o -name "docker*" -o -name "package.json" \) | head -20
echo ""
echo "=== Checking for env validation or config loading ==="
rg -n "SUBDOMAIN|DOMAIN" --type ts --type tsx --type js --type json -B2 -A2 | head -60
echo ""
echo "=== How is wsUrl used on client side? ==="
rg -n "wsUrl" --type ts --type tsx --type js -B2 -A2Repository: openfrontio/OpenFrontIO
Length of output: 306
🏁 Script executed:
# Check example.env for required vars
echo "=== example.env content ==="
cat ./example.env
echo ""
echo "=== RenderHtml.ts full context around wsUrl ==="
cat -n src/server/RenderHtml.ts | head -50
echo ""
echo "=== Search for wsUrl usage (in templates and html files) ==="
rg -n "wsUrl" --type ts --type js
echo ""
echo "=== Look for any validation or env setup code ==="
rg -n "SUBDOMAIN|DOMAIN" -B3 -A3 --type ts --type jsRepository: openfrontio/OpenFrontIO
Length of output: 6513
🏁 Script executed:
# Check if there's a reason RenderHtml.ts doesn't use the config layer
echo "=== Check DefaultConfig imports in other files ==="
rg -n "DefaultConfig\|from.*configuration" src/server/ --type ts | head -20
echo ""
echo "=== Check what getEnv function does ==="
rg -n "function getEnv\|const getEnv" --type ts -A5Repository: openfrontio/OpenFrontIO
Length of output: 158
🏁 Script executed:
# Read the Env.ts file to understand the config pattern
echo "=== Env.ts content ==="
cat -n src/core/configuration/Env.ts
echo ""
echo "=== First 40 lines of DefaultConfig.ts ==="
head -40 src/core/configuration/DefaultConfig.tsRepository: openfrontio/OpenFrontIO
Length of output: 3973
Add validation for required WebSocket URL environment variables.
Line 29 builds wsUrl directly from SUBDOMAIN and DOMAIN without checking if they exist. If either is undefined, clients will connect to an invalid URL like "undefined.domain.com". Note that example.env does not define SUBDOMAIN, so this will fail in new environments.
The codebase already uses fallback patterns for other env vars (see GIT_COMMIT ?? "undefined" on line 17 and GAME_ENV ?? "dev" on line 19). Apply the same pattern here:
Proposed fix
- wsUrl: JSON.stringify(`${process.env.SUBDOMAIN}.${process.env.DOMAIN}`),
+ wsUrl: JSON.stringify(
+ process.env.SUBDOMAIN && process.env.DOMAIN
+ ? `${process.env.SUBDOMAIN}.${process.env.DOMAIN}`
+ : process.env.DOMAIN ?? "localhost:3000",
+ ),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/server/RenderHtml.ts` at line 29, The wsUrl build in RenderHtml.ts uses
SUBDOMAIN and DOMAIN without validation; update the wsUrl assignment (the wsUrl
property construction) to use safe fallbacks like SUBDOMAIN ?? "undefined" and
DOMAIN ?? "undefined" (or a sensible default) before JSON.stringify so clients
don't get "undefined.domain.com"; ensure you reference process.env.SUBDOMAIN and
process.env.DOMAIN and apply the same fallback pattern used for GIT_COMMIT and
GAME_ENV.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/client/LobbySocket.ts (1)
56-59: Add fallback ifwindow.WS_URLis not defined.If the server fails to inject
window.WS_URLor the page loads in an unexpected context, this will produce an invalid URL likewss://undefined/.... Consider falling back towindow.location.host.🛠️ Suggested fix
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - const wsUrl = `${protocol}//${window.WS_URL}/${this.workerPath}/lobbies`; + const host = window.WS_URL || window.location.host; + const wsUrl = `${protocol}//${host}${this.workerPath}/lobbies`;Also note:
this.workerPathalready starts with/(fromgetRandomWorkerPath), so the extra/before it creates a double-slash in the path. The fix above removes that redundant slash.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/client/LobbySocket.ts` around lines 56 - 59, The WebSocket URL construction in LobbySocket (the protocol/wsUrl creation and new WebSocket call) can produce invalid URLs when window.WS_URL is undefined and also introduces a double-slash because this.workerPath already starts with "/"; update the wsUrl logic to fall back to window.location.host when window.WS_URL is falsy (use window.WS_URL || window.location.host) and concatenate the host and workerPath without adding an extra "/" before this.workerPath so the final wsUrl uses `${protocol}//${host}${this.workerPath}/lobbies` before calling new WebSocket(wsUrl).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/client/LobbySocket.ts`:
- Around line 56-59: The WebSocket URL construction in LobbySocket (the
protocol/wsUrl creation and new WebSocket call) can produce invalid URLs when
window.WS_URL is undefined and also introduces a double-slash because
this.workerPath already starts with "/"; update the wsUrl logic to fall back to
window.location.host when window.WS_URL is falsy (use window.WS_URL ||
window.location.host) and concatenate the host and workerPath without adding an
extra "/" before this.workerPath so the final wsUrl uses
`${protocol}//${host}${this.workerPath}/lobbies` before calling new
WebSocket(wsUrl).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1c120942-5948-4010-80db-439b0f0e0294
📒 Files selected for processing (6)
index.htmlsrc/client/LobbySocket.tssrc/client/Main.tssrc/client/Transport.tssrc/server/RenderHtml.tsvite.config.ts
✅ Files skipped from review due to trivial changes (1)
- src/client/Transport.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/server/RenderHtml.ts
- vite.config.ts
- src/client/Main.ts
- index.html
If this PR fixes an issue, link it below. If not, delete these two lines.
Resolves #(issue number)
Description:
Describe the PR.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
DISCORD_USERNAME