|
| 1 | +"""octofit_tracker URL Configuration |
| 2 | +
|
| 3 | +The `urlpatterns` list routes URLs to views. For more information please see: |
| 4 | + https://docs.djangoproject.com/en/4.1/topics/http/urls/ |
| 5 | +Examples: |
| 6 | +Function views |
| 7 | + 1. Add an import: from my_app import views |
| 8 | + 2. Add a URL to urlpatterns: path('', views.home, name='home') |
| 9 | +Class-based views |
| 10 | + 1. Add an import: from other_app.views import Home |
| 11 | + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') |
| 12 | +Including another URLconf |
| 13 | + 1. Import the include() function: from django.urls import include, path |
| 14 | + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
| 15 | +""" |
| 16 | +import os |
| 17 | +from django.contrib import admin |
| 18 | +from django.urls import path |
| 19 | +from django.http import JsonResponse |
| 20 | + |
| 21 | +def api_root(request): |
| 22 | + codespace_name = os.environ.get('CODESPACE_NAME', '') |
| 23 | + base_url = f"https://{codespace_name}-8000.app.github.dev" if codespace_name else "http://localhost:8000" |
| 24 | + return JsonResponse({ |
| 25 | + "users": f"{base_url}/api/users/", |
| 26 | + "teams": f"{base_url}/api/teams/", |
| 27 | + "activities": f"{base_url}/api/activities/", |
| 28 | + "leaderboard": f"{base_url}/api/leaderboard/", |
| 29 | + "workouts": f"{base_url}/api/workouts/", |
| 30 | + }) |
| 31 | + |
| 32 | +urlpatterns = [ |
| 33 | + path('admin/', admin.site.urls), |
| 34 | + path('', api_root, name='api_root'), |
| 35 | +] |
0 commit comments