Skip to content

Serve docs via public/private symlinks, instead of built doc paths. #2191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4fe48d1
Move urls & views into subdirectories
ericholscher Apr 22, 2016
09188b5
Update to use fancy URL's and whatnot
ericholscher Apr 22, 2016
9657816
Fix small tests
ericholscher Apr 22, 2016
ce68cc7
Futz around with more tests and cleanup
ericholscher Apr 25, 2016
64faed2
Remove old files
ericholscher Apr 26, 2016
4f38799
Fix url tests
ericholscher Apr 26, 2016
8584c1f
Fix up tests
ericholscher Apr 26, 2016
0dead74
Test 404 handling
ericholscher Apr 26, 2016
29c9576
Serve media in subdomains during DEBUG
ericholscher May 2, 2016
8e69581
Add support for *.dev.readthedocs.io
ericholscher May 2, 2016
ecdbeb7
Handle media on subdomains.
ericholscher May 2, 2016
3a310d4
Add default SERVE_DOCS
ericholscher May 2, 2016
f1a2ed5
Fix a few tests
ericholscher May 2, 2016
18e3f88
Remove unused tests
ericholscher May 2, 2016
c6b4327
More test fixing
ericholscher May 2, 2016
99f3682
Fix linting error
ericholscher May 2, 2016
9c1c3ab
Fix redirects
ericholscher May 2, 2016
a055eaf
Fix silly error
ericholscher May 2, 2016
90f1d2b
Include search urls in subdomains/single version
ericholscher May 2, 2016
6767e58
Don’t include any URL’s in sub/single
ericholscher May 2, 2016
4634e7c
Merge remote-tracking branch 'origin/master' into symlink-serving
ericholscher May 3, 2016
4a162e3
Merge remote-tracking branch 'origin/master' into break-out-core-urls…
ericholscher May 3, 2016
faf90d4
Add small commit to force GH rebuild
ericholscher May 3, 2016
31d9c1c
Respect privacy with doc serving.
ericholscher May 3, 2016
2d08797
Little refactor of doc serving code
ericholscher May 3, 2016
4ac2fa9
Keep smaller lines
ericholscher May 3, 2016
027f143
Add env to ignore list
ericholscher May 3, 2016
b08d1b7
Merge remote-tracking branch 'origin/break-out-core-urls-views' into …
ericholscher May 3, 2016
4f15dfb
Remove extra space
ericholscher May 3, 2016
4e5cc83
Fix up tests
ericholscher May 3, 2016
da00361
Don't overload `internal` with .com
ericholscher May 3, 2016
73dcab3
Support subprojects
ericholscher May 4, 2016
097a410
Fully port subproject URL's
ericholscher May 4, 2016
f2ee674
Clean up tests
ericholscher May 4, 2016
900d456
Fix linting
ericholscher May 4, 2016
bf76ec7
Fix random tests
ericholscher May 4, 2016
5c80b3a
CLean up lying comments and require privacy
ericholscher May 4, 2016
54ae5e4
Pass privacy_level explicitly
ericholscher May 4, 2016
828448c
Fix linting
ericholscher May 4, 2016
c81f118
Make is_member work on .com as well
ericholscher May 4, 2016
1e1474c
Fix test
ericholscher May 4, 2016
ff3c5ae
Use DEV_DOMAIN instead of DEV_URL
ericholscher May 4, 2016
f27a37b
Remove DEV_DOMAIN
ericholscher May 4, 2016
fe2c12d
Fix logic here
ericholscher May 4, 2016
8bae094
Fix and/or logic
ericholscher May 4, 2016
2f5a268
Fix linting on production_domain again
ericholscher May 4, 2016
ceef1c3
Merge branch 'symlink-serving' into privacy-symlink-serving
ericholscher May 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.idea
.vagrant
.tox
.env
.rope_project/
.ropeproject/
_build
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ when you push to GitHub.
:alt: Documentation Status
:scale: 100%
:target: https://docs.readthedocs.io/en/latest/?badge=latest

1 change: 0 additions & 1 deletion readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from readthedocs.projects.constants import (PRIVACY_CHOICES, GITHUB_URL,
GITHUB_REGEXS, BITBUCKET_URL,
BITBUCKET_REGEXS, PRIVATE)
from readthedocs.core.resolver import resolve

from .constants import (BUILD_STATE, BUILD_TYPES, VERSION_TYPES,
LATEST, NON_REPOSITORY_VERSIONS, STABLE,
Expand Down
26 changes: 16 additions & 10 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.sessions.middleware import SessionMiddleware
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.http import Http404
from django.http import Http404, HttpResponseBadRequest

from readthedocs.projects.models import Project, Domain

Expand All @@ -15,12 +15,12 @@
SUBDOMAIN_URLCONF = getattr(
settings,
'SUBDOMAIN_URLCONF',
'readthedocs.core.subdomain_urls'
'readthedocs.core.urls.subdomain'
)
SINGLE_VERSION_URLCONF = getattr(
settings,
'SINGLE_VERSION_URLCONF',
'readthedocs.core.single_version_urls'
'readthedocs.core.urls.single_version'
)


Expand All @@ -30,12 +30,15 @@ def process_request(self, request):
if not getattr(settings, 'USE_SUBDOMAIN', False):
return None

host = request.get_host().lower()
full_host = host = request.get_host().lower()
path = request.get_full_path()
log_kwargs = dict(host=host, path=path)
public_domain = getattr(settings, 'PUBLIC_DOMAIN', None)
production_domain = getattr(settings, 'PRODUCTION_DOMAIN',
'readthedocs.org')
production_domain = getattr(
settings,
'PRODUCTION_DOMAIN',
'readthedocs.org'
)

if public_domain is None:
public_domain = production_domain
Expand All @@ -47,12 +50,15 @@ def process_request(self, request):
if len(domain_parts) == len(public_domain.split('.')) + 1:
subdomain = domain_parts[0]
is_www = subdomain.lower() == 'www'
is_ssl = subdomain.lower() == 'ssl'
if not is_www and not is_ssl and public_domain in host:
if not is_www and (
# Support ports during local dev
public_domain in host or public_domain in full_host
):
request.subdomain = True
request.slug = subdomain
request.urlconf = SUBDOMAIN_URLCONF
return None

# Serve CNAMEs
if (public_domain not in host and
production_domain not in host and
Expand Down Expand Up @@ -103,11 +109,11 @@ def process_request(self, request):
raise Http404(_('Invalid hostname'))
# Google was finding crazy www.blah.readthedocs.org domains.
# Block these explicitly after trying CNAME logic.
if len(domain_parts) > 3:
if len(domain_parts) > 3 and not settings.DEBUG:
# Stop www.fooo.readthedocs.org
if domain_parts[0] == 'www':
log.debug(LOG_TEMPLATE.format(msg='404ing long domain', **log_kwargs))
raise Http404(_('Invalid hostname'))
return HttpResponseBadRequest(_('Invalid hostname'))
log.debug(LOG_TEMPLATE.format(msg='Allowing long domain name', **log_kwargs))
# raise Http404(_('Invalid hostname'))
# Normal request.
Expand Down
6 changes: 5 additions & 1 deletion readthedocs/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def resolve_path(self, project, filename='', version_slug=None,
single_version=single_version,
subproject_slug=subproject_slug,
cname=cname,
private=private
private=private,
subdomain=subdomain,
)

def resolve_domain(self, project, private=None):
Expand Down Expand Up @@ -181,6 +182,9 @@ def _fix_filename(self, project, filename):

This basically means stripping / and .html endings and then re-adding them properly.
"""
# Bail out on non-html files
if '.' in filename and '.html' not in filename:
return filename
filename = filename.lstrip('/')
filename = re.sub('index.html$', '', filename)
filename = re.sub('index$', '', filename)
Expand Down
14 changes: 0 additions & 14 deletions readthedocs/core/single_version_urls.py

This file was deleted.

48 changes: 0 additions & 48 deletions readthedocs/core/subdomain_urls.py

This file was deleted.

102 changes: 0 additions & 102 deletions readthedocs/core/urls.py

This file was deleted.

71 changes: 71 additions & 0 deletions readthedocs/core/urls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from django.conf.urls import url, patterns

from readthedocs.constants import pattern_opts
from readthedocs.builds.filters import VersionFilter
from readthedocs.projects.feeds import LatestProjectsFeed, NewProjectsFeed
from readthedocs.projects.filters import ProjectFilter


docs_urls = patterns(
'',

url((r'^docs/(?P<project_slug>{project_slug})/page/'
r'(?P<filename>{filename_slug})$'.format(**pattern_opts)),
'readthedocs.core.views.serve.redirect_page_with_filename',
name='docs_detail'),

url((r'^docs/(?P<project_slug>{project_slug})/'
r'(?:|projects/(?P<subproject_slug>{project_slug})/)$'.format(**pattern_opts)),
'readthedocs.core.views.serve.redirect_project_slug',
name='docs_detail'),

url((r'^docs/(?P<project_slug>{project_slug})/'
r'(?:|projects/(?P<subproject_slug>{project_slug})/)'
r'(?P<lang_slug>{lang_slug})/'
r'(?P<version_slug>{version_slug})/'
r'(?P<filename>{filename_slug})'.format(**pattern_opts)),
'readthedocs.core.views.serve.serve_docs',
name='docs_detail'),
)


core_urls = patterns(
'',
# Hooks
url(r'^github', 'readthedocs.core.views.hooks.github_build', name='github_build'),
url(r'^gitlab', 'readthedocs.core.views.hooks.gitlab_build', name='gitlab_build'),
url(r'^bitbucket', 'readthedocs.core.views.hooks.bitbucket_build', name='bitbucket_build'),
url((r'^build/'
r'(?P<project_id_or_slug>{project_slug})'.format(**pattern_opts)),
'readthedocs.core.views.hooks.generic_build',
name='generic_build'),
# Random other stuff
url(r'^random/(?P<project_slug>{project_slug})'.format(**pattern_opts),
'readthedocs.core.views.random_page',
name='random_page'),
url(r'^random/$', 'readthedocs.core.views.random_page', name='random_page'),
url(r'^500/$', 'readthedocs.core.views.divide_by_zero', name='divide_by_zero'),
url((r'^wipe/(?P<project_slug>{project_slug})/'
r'(?P<version_slug>{version_slug})/$'.format(**pattern_opts)),
'readthedocs.core.views.wipe_version',
name='wipe_version'),
)

deprecated_urls = patterns(
'',
url(r'^filter/version/$',
'django_filters.views.object_filter',
{'filter_class': VersionFilter, 'template_name': 'filter.html'},
name='filter_version'),
url(r'^filter/project/$',
'django_filters.views.object_filter',
{'filter_class': ProjectFilter, 'template_name': 'filter.html'},
name='filter_project'),

url(r'^feeds/new/$',
NewProjectsFeed(),
name="new_feed"),
url(r'^feeds/latest/$',
LatestProjectsFeed(),
name="latest_feed"),
)
Loading