Enable Cloud-Based Development with Codespaces#58
Open
collisdigital wants to merge 8 commits intohunvreus:developmentfrom
Open
Enable Cloud-Based Development with Codespaces#58collisdigital wants to merge 8 commits intohunvreus:developmentfrom
collisdigital wants to merge 8 commits intohunvreus:developmentfrom
Conversation
* refactor: use relative URLs for internal links and redirects Updates the application to use relative URLs for internal navigation and redirects, fixing issues with dynamic hostnames in environments like GitHub Codespaces. - Introduced `RelativeURL` wrapper and `rel_url_for` helper. - Introduced `get_app_base_url` for resolving absolute URLs using `X-Forwarded-Host`. - Refactored templates to use `rel_url_for`. - Refactored routers to use relative URLs for redirects and `get_app_base_url` for emails/OAuth. - Introduced `get_absolute_url` helper to reduce duplication. - Introduced `get_email_logo_url` helper. - Updated routers to use the new helpers. - Updated `get_app_base_url`, `get_absolute_url`, and `get_email_logo_url` to accept an optional `client_origin` argument. - Implemented logic to prioritize `client_origin` (from frontend) when `APP_HOSTNAME` is a localhost variant, ensuring correct links in development environments like Codespaces. - Updated authentication, user settings (email change), and team settings (add member) routers to pass the `client_origin` from the form data to the URL generation helpers. - This ensures email links point to the correct external domain (e.g. the Codespaces proxy URL) rather than the internal container hostname. * fix: handle missing oauth configuration gracefully - Added checks for `oauth_client` being `None` in `app/routers/google.py`, `app/routers/github.py`, and `app/routers/auth.py` before accessing attributes. - This prevents `AttributeError: 'NoneType' object has no attribute 'google'` (or 'github') when the respective OAuth provider is not configured. - This ensures the application starts and handles missing configuration correctly, redirecting or showing an error message instead of crashing. * Update README and lib.sh to clarify Codespaces setup and dev mode --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: collisdigital <14041600+collisdigital@users.noreply.github.com>
* Fix Google OAuth redirect URI for dynamic hostnames (e.g. Codespaces) Pass `client_origin` from frontend to backend during Google OAuth initiation. Store `client_origin` in session and use it to construct the correct `redirect_uri` for both authorization and token exchange. This resolves issues where `localhost` was used instead of the dynamic public URL. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: collisdigital <14041600+collisdigital@users.noreply.github.com>
* feat: implement interactive Python debugging for 'app' service - Modify `compose/override.dev.yml` to expose port 5678 for the `app` service. - Update `docker/entrypoint.app.dev.sh` to conditionally run `debugpy` if `DEBUG=true`. - Create `.vscode/launch.json` with "Python: Remote Attach" configuration. - Update `.devcontainer.json` to install `ms-python.debugpy` and forward ports 5678 and 8000. - Update `README.md` with instructions on how to use debugging. * Fix Google Auth bug - redirect was set to invalid URL (missing '/user/') and callback code was wrong (reverted previous change) --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: collisdigital <14041600+collisdigital@users.noreply.github.com>
* fix(auth): support dynamic origin for GitHub OAuth Update GitHub OAuth flow to support client-side origin resolution, enabling correct redirect URIs when running in environments like GitHub Codespaces. - Update `github_authorize` to accept and store `client_origin`. - Update frontend templates to pass `client_origin` via `onclick` handler in GitHub Connect buttons. - Use `get_absolute_url` for consistent URL generation. --------- Co-authored-by: collisdigital <14041600+collisdigital@users.noreply.github.com>
Removed redundant steps in the debugging instructions for clarity.
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.
Summary
This PR introduces full support for cloud-based development using VS Code Codespaces and local Dev Containers. It addresses the limitation where the application relies on absolute URLs which caused breakages when running behind port-forwarding proxies in the cloud.
Key Changes
1. Cloud-Native Development Infrastructure
postCreateCommandto bootstrap thedata/directory and initialize the.envfile.debugpy(attach a Python debugger to the running app in the container).2. Transition to Relative URLs
Standard
url_forhelpers in FastAPI/Starlette generate absolute URLs by default. In Codespaces, these URLs often point to the internal container port (e.g.,http://localhost:80), which fails when accessed via the forwarded public URL.RelativeURLutility andrel_url_fortemplate helper in app/dependencies.py to generate path-only URLs (e.g.,/login).3. Dynamic Base URL Resolution
For scenarios where absolute URLs are strictly required (OAuth callbacks for GitHub/Google, email magic links, and SSE logic):
get_app_base_urlin app/utils/urls.py, which intelligently resolves the public endpoint by checkingX-Forwarded-HostandX-Forwarded-Protoheaders set by Codespaces and Traefik.4. Enhanced Security & Redirection
safe_redirecthelper in app/utils/urls.py to validate redirect targets. This prevents open-redirect vulnerabilities by ensuringnextparameters are either relative or strictly same-origin.5. Updated Documentation
Benefits
How to Test
.devcontainerfile doesn't exist in the upstream repository yet, you will need to go to the branch this PR is based on: https://github.com/collisdigital/devpush/tree/feat/devcontainer-setup<> Codemenu:data/.envas usual and start the appscripts/start.shfrom the integrated Terminal (CMD-J).https://glorious-cod-7vp76vvw9gpcwrvv-80.app.github.dev/auth/loginor similar (this is the same as a localhttp://localhost:80/auth/loginstart.shNote: This PR involves widespread changes to templates and routers to ensure consistent URL handling throughout the codebase.