From e6b02555f4aa6040f39a35b6d96754b7850e0a47 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 3 Nov 2023 16:08:31 -0700 Subject: [PATCH] =?UTF-8?q?Github=20Codespaces=20Support=20=F0=9F=AA=90=20?= =?UTF-8?q?(#2125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/devcontainer.json | 14 ++++++++++++++ reflex/config.py | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..9b9da13b2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" + } + } +} diff --git a/reflex/config.py b/reflex/config.py index 5f135f08e..a496dd311 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -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.