Skip to content

Commit 9ef39e1

Browse files
committed
Update launch configuration and settings for CODESPACE support
- Adjust Python path in launch.json for consistent environment setup. - Modify ALLOWED_HOSTS in settings.py to include localhost and CODESPACE_NAME. - Update api_root function in urls.py to generate base URL based on CODESPACE_NAME.
1 parent a4caa1d commit 9ef39e1

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.vscode/launch.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"args": ["runserver", "0.0.0.0:8000"],
1010
"django": true,
1111
"justMyCode": true,
12-
"python": "${workspaceFolder}/octofit-tracker/backend/venv/bin/python",
12+
"python": "/workspaces/skills-build-applications-w-copilot-agent-mode/.venv/bin/python",
1313
"env": {
14-
"PYTHONPATH": "${workspaceFolder}/octofit-tracker/backend/venv/bin/python",
15-
"VIRTUAL_ENV": "${workspaceFolder}/octofit-tracker/backend/venv",
16-
"PATH": "${workspaceFolder}/octofit-tracker/backend/venv/bin:${env:PATH}"
14+
"CODESPACE_NAME": "${env:CODESPACE_NAME}",
15+
"PYTHONPATH": "/workspaces/skills-build-applications-w-copilot-agent-mode/.venv/bin/python",
16+
"VIRTUAL_ENV": "/workspaces/skills-build-applications-w-copilot-agent-mode/.venv",
17+
"PATH": "/workspaces/skills-build-applications-w-copilot-agent-mode/.venv/bin:${env:PATH}"
1718
}
1819
},
1920
{

octofit-tracker/backend/octofit_tracker/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = ['*']
28+
import os
29+
CODESPACE_NAME = os.environ.get('CODESPACE_NAME')
30+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
31+
if CODESPACE_NAME:
32+
ALLOWED_HOSTS.append(f"{CODESPACE_NAME}-8000.app.github.dev")
2933

3034

3135
# Application definition

octofit-tracker/backend/octofit_tracker/urls.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@
3030

3131
@api_view(['GET'])
3232
def api_root(request, format=None):
33+
import os
34+
codespace_name = os.environ.get('CODESPACE_NAME', None)
35+
if codespace_name:
36+
base_url = f"https://{codespace_name}-8000.app.github.dev/api/"
37+
else:
38+
base_url = request.build_absolute_uri('/').rstrip('/') + '/api/'
3339
return Response({
34-
'users': request.build_absolute_uri('/users/'),
35-
'teams': request.build_absolute_uri('/teams/'),
36-
'activities': request.build_absolute_uri('/activities/'),
37-
'leaderboard': request.build_absolute_uri('/leaderboard/'),
38-
'workouts': request.build_absolute_uri('/workouts/'),
40+
'users': base_url + 'users/',
41+
'teams': base_url + 'teams/',
42+
'activities': base_url + 'activities/',
43+
'leaderboard': base_url + 'leaderboard/',
44+
'workouts': base_url + 'workouts/',
3945
})
4046

4147
urlpatterns = [

0 commit comments

Comments
 (0)