-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fc4e19
commit 3cada1d
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from rest_framework import decorators, permissions, status | ||
from rest_framework.renderers import JSONPRenderer, JSONRenderer, BrowsableAPIRenderer | ||
from rest_framework.response import Response | ||
|
||
from core.utils import clean_url, cname_to_slug | ||
from projects.models import Project | ||
|
||
@decorators.api_view(['GET']) | ||
@decorators.permission_classes((permissions.AllowAny,)) | ||
@decorators.renderer_classes((JSONRenderer, JSONPRenderer, BrowsableAPIRenderer)) | ||
def cname(request): | ||
""" | ||
Get the slug that a particular hostname resolves to. | ||
This is useful for debugging your DNS settings, | ||
or for getting the backing project name on Read the Docs for a URL. | ||
Example:: | ||
GET https://readthedocs.org/api/v2/cname/?host=docs.python-requests.org | ||
This will return information about ``docs.python-requests.org`` | ||
""" | ||
host = request.GET.get('host') | ||
if not host: | ||
return Response({'error': 'host GET arg required'}, status=status.HTTP_400_BAD_REQUEST) | ||
host = clean_url(host) | ||
slug = cname_to_slug(host) | ||
return Response({ | ||
'host': host, | ||
'slug': slug, | ||
}) | ||
|
||
|