fix: use codespace-aware URLs for Vite dev assets#52637
Draft
fix: use codespace-aware URLs for Vite dev assets#52637
Conversation
Contributor
|
Size Change: 0 B Total Size: 124 MB ℹ️ View Unchanged
|
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
PostHog renders a blank page when accessed via GitHub Codespaces. The Django backend correctly sets
window.JS_URLto the Codespace-forwarded origin, but the Vite dev script tags (@react-refresh,@vite/client,src/index.tsx) are hardcoded tohttp://localhost:8234, which is unreachable from the browser in Codespaces where forwarded ports use the patternhttps://<CODESPACE_NAME>-<PORT>.<DOMAIN>.Changes
Four independent
http://localhost:8234references replaced with Codespace-aware equivalents:posthog/settings/__init__.py-- Auto-detect Codespace viaCODESPACE_NAMEandGITHUB_CODESPACES_PORT_FORWARDING_DOMAINenv vars (set automatically by GitHub) to construct the correct defaultJS_URLposthog/utils.py--vite_dev_scriptsnow usesget_js_url(request)instead of hardcodinglocalhost
posthog/middleware.py-- CSPresource_urlandconnect_debug_urlderive fromsettings.JS_URL, usingwss://for HTTPS originsfrontend/vite.config.ts--server.originandserver.hostare Codespace-aware for correct HMR asset URL generationLocal dev behavior is unchanged -- all defaults remain
http://localhost:8234when the Codespace env vars are absent.How did you test this code?
JS_URLresolves correctly in both environments:http://localhost:8234CODESPACE_NAME=test GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=app.github.dev):https://test-8234.app.github.devTestCSPMiddleware)ruff check)Publish to changelog?
No
Docs update
N/A