Skip to content

Commit e6b0255

Browse files
authored
Github Codespaces Support 🪐 (#2125)
1 parent 6e1bce3 commit e6b0255

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
3+
"postCreateCommand": "/bin/bash -c 'python -m pip install poetry && python -m poetry install & git clone https://github.com/reflex-dev/reflex-examples; wait'",
4+
"forwardPorts": [3000, 8000],
5+
"portsAttributes": {
6+
"3000": {
7+
"label": "Frontend",
8+
"onAutoForward": "notify"
9+
},
10+
"8000": {
11+
"label": "Backend"
12+
}
13+
}
14+
}

reflex/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ def _replace_defaults(self, **kwargs):
314314
):
315315
self.deploy_url = f"http://localhost:{kwargs['frontend_port']}"
316316

317+
# If running in Github Codespaces, override API_URL
318+
codespace_name = os.getenv("CODESPACE_NAME")
319+
if "api_url" not in self._non_default_attributes and codespace_name:
320+
GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN = os.getenv(
321+
"GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"
322+
)
323+
if codespace_name:
324+
self.api_url = (
325+
f"https://{codespace_name}-{kwargs.get('backend_port', self.backend_port)}"
326+
f".{GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
327+
)
328+
317329
def _set_persistent(self, **kwargs):
318330
"""Set values in this config and in the environment so they persist into subprocess.
319331

0 commit comments

Comments
 (0)