-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add ability for users to set their own URLConf #6963
Conversation
This lets users configure how they want their URLs to look. This could include not having a version or language, or having a different subpath for subprojects. Refences #6868
readthedocs/proxito/middleware.py
Outdated
urlpatterns = [ | ||
re_path(project.real_urlconf, ServeDocs.as_view()), | ||
re_path('^' + project.real_urlconf, ServeDocs.as_view()), | ||
re_path('^/' + project.real_urlconf, ServeDocs.as_view()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to bring in the 404, 500, and all of the proxito urls here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agjohnson I didn't need the 404/500 yet, but I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone ahead and added them.
readthedocs/proxito/middleware.py
Outdated
) | ||
|
||
# Stop Django from caching URLs | ||
ns = time.mktime(time.gmtime()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be the model modified date probably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable approach. Manually manipulating sys.modules could be fragile, though I don't have a good idea of what exactly our concerns would be here. If we have concerns, we could dynamically instantiate objects once on startup, giving real dotted paths to these objects for request.urlconf. I'm not too worried unless someone has a good idea of the downfalls of patching sys.modules on each request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested yet locally, but it seems it works.
I'd like to understand more the approach we are following and why. I left some questions for this.
Also, I made some suggestions to improve code readability since it took me some time to realize what was each thing --they have names that are confusing to me. Would be good if we can improve the naming before merging.
readthedocs/projects/models.py
Outdated
null=True, | ||
help_text=_( | ||
'Supports the following keys: $language, $version, $subproject, $filename. ' | ||
'An example `$language/$version/$filename`.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'An example `$language/$version/$filename`.' | |
'Default: `$language/$version/$filename`. ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Default:
is better here? There isn't a default for this field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that URL is what Read the Docs uses by default: /en/latest/filename.html
. It's not the default of the field, but that's the help text presented to the user.
url_prefix = self.urlconf.split('$', 1)[0] | ||
return '/' + url_prefix.strip('/') + '/_' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to understand what this method does. Can you expand the docstring and add an example?
It seems like /hello/$language/
will be /hello/_
, is that correct? In that case, why do we need this?
Also, that seems more like a path than a host. We should change the name in that case, maybe url_prefix
or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What part don't you understand? It's passed as proxied_api_host
in JS, which is where we hit the backend proxied API's.
It's a path in this case, but it can also be a fully formed URL, so we're using the existing name.
readthedocs/projects/models.py
Outdated
r'{proxied_api_url}api/v2/'.format(proxied_api_url=self.proxied_api_url), | ||
include('readthedocs.api.v2.proxied_urls'), | ||
name='fake_proxied_api' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to proxy these URLs with /hello/_/
prefix (following my previous comment)? Why not just use _/
as we are currently doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we need to be able to support proxied API's at non-root URLs for a users who want to use a proxied subpath docs.company.com/rtd-hosted-project/_/
Co-authored-by: Manuel Kaufmann <[email protected]>
…org into project-urlconf
Co-authored-by: Manuel Kaufmann <[email protected]>
This lets users configure how they want their URLs to look.
This could include not having a version or language,
or having a different subpath for subprojects.
Refences #6868
Example
This serves docs from
http://kong.community.dev.readthedocs.io/latest/index.html
by settingsproject.urlconf = '$version/$filename
.From the logs:
TODO
There's still a bunch of work we need to do to make this work: