Skip to content

Support running smallweb in Codespaces/Codesandbox/cloud IDEs: HTTP-only mode, proxy-aware base URLs #98

@public-rant

Description

@public-rant

Many developers use cloud IDEs such as GitHub Codespaces or Codesandbox to test and develop smallweb apps. These environments enforce HTTPS via their own reverse proxies and generate preview domains like:

  • Codespaces: https://fuzzy-space-waddle-abc123-8080.app.github.dev
  • Codesandbox: https://abc123-8080.csb.app
  • Gitpod: https://8080-workspace-abc123.ws-eu54.gitpod.io

All client requests are routed to the exposed port in the development container (which typically serves plain HTTP). The platform then terminates HTTPS, injects its own certificate, and forwards traffic to the container. This brings a few challenges:

Current Issues:

  • If smallweb serves HTTPS internally, the cert will never match the external preview domain, leading to browser errors and configuration complexity.
  • Apps may construct links or OAuth redirect URIs using localhost or the internal port, which will fail because the user sees the public preview domain.
  • Cloud IDE proxies forward headers such as Host and X-Forwarded-Proto for reconstructing the correct external base URL, but smallweb may not always leverage these for correct user links or redirects.
  • OAuth flows and third-party integrations are particularly affected by incorrect or inconsistent base URL computation.

Feature Request:

  • Add a config flag (e.g. --env codespace/--env sandbox or via config file) to:
    • Always run smallweb?s internal server in plain HTTP mode in known cloud IDE environments (optionally emit a notice about HTTPS being handled externally).
    • Correctly reconstruct all external links and OAuth redirect URIs using X-Forwarded-Proto and Host headers.
    • Document guidelines for using smallweb in Codespaces/Codesandbox/Gitpod-like environments (including environment variable tips).
  • Auto-detection Suggestion: in the future, support auto-detecting known environments using variables such as:
    • CODESPACES (GitHub Codespaces)
    • CODESANDBOX_HOST (Codesandbox)
    • GITPOD_WORKSPACE_URL (Gitpod)

Proposed Example Config:

{
  "cloudIDE": true,
  "trustProxyHeaders": true
}

(open to other config names/formats matching project standards)

Benefits:

  • Eases onboarding and reduces surprises for cloud IDE users.
  • Prevents TLS/cert errors and broken links/redirects in supported workflows.
  • Makes smallweb robust and portable in modern cloud-based development scenarios.

Planned and Possible Future Enhancements:

  • Automatic environment detection based on env vars (for "it just works" experience).
  • Optionally display a banner or log notice when running in a detected cloud IDE environment.
  • Automatic fallback to best-practice base URL/path heuristics for unfamiliar proxy environments.

References:

  • Many cloud IDEs forward these headers for reconstructing user-facing URLs: Host, X-Forwarded-Proto, X-Forwarded-Host
  • Relevant for OAuth, OpenID Connect, SSO, and other flows sensitive to canonical URLs.

I'm happy to help clarify use-cases, share more environment examples, or test any proposed solution. Thank you for your work on smallweb!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions