Github Codespaces Support 🪐 (#2125)

This commit is contained in:
Masen Furer 2023-11-03 16:08:31 -07:00 committed by GitHub
parent 6e1bce3412
commit e6b02555f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,14 @@
{
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
"postCreateCommand": "/bin/bash -c 'python -m pip install poetry && python -m poetry install & git clone https://github.com/reflex-dev/reflex-examples; wait'",
"forwardPorts": [3000, 8000],
"portsAttributes": {
"3000": {
"label": "Frontend",
"onAutoForward": "notify"
},
"8000": {
"label": "Backend"
}
}
}

View File

@ -314,6 +314,18 @@ class Config(Base):
):
self.deploy_url = f"http://localhost:{kwargs['frontend_port']}"
# If running in Github Codespaces, override API_URL
codespace_name = os.getenv("CODESPACE_NAME")
if "api_url" not in self._non_default_attributes and codespace_name:
GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN = os.getenv(
"GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"
)
if codespace_name:
self.api_url = (
f"https://{codespace_name}-{kwargs.get('backend_port', self.backend_port)}"
f".{GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
)
def _set_persistent(self, **kwargs):
"""Set values in this config and in the environment so they persist into subprocess.