Add top level rails application url - #42520
Conversation
|
@aka47 Thanks for contributing to Rails! |
|
Thanks @p8. It's a start and I am happy to learn and add possible and more PR to rails in the future. Some parts of the PR from @vipulnsward could be merged into this one, setting the default-url-options for one. I will do that. It has 2 failing tests - which have the same root cause - I will fix those some time soon. |
|
Vipul said he would look into updating his PR soon, let's give him a chance to pick up where he left off 🙏 |
I am more than happy to work with @vipulnsward on this PR. Vipul - lets not do the same work twice, lets better work together on it? How about that? |
|
@ak15 you can take over if you are interested. I have been caught up in work, so might not get to it soon. |
|
What are the next steps here? @p8 / @marivaldo - please help me out here. I am happy to do some more work, tune it, but I need someone who gives me a path to its being merged. That would be wonderful. Working on this task I got the impression this could need some more follow up refactoring - as this part is very complex and interdependent. If this should be part of this PR - I would love to have someone with whom I could share my ideas for it and come an agreement together. So - should we just bring this to a quick end and merge it? Or what is the plan here forward? .. Thanks a lot .. |
f191756 to
3111880
Compare
8333a91 to
8865a99
Compare
|
@p8 thanks for your feedback. I took your feedback and changed quit some parts of this PR.
What you think? Any other remarks from your side? ( or Are we good to go? :) |
c41ce80 to
604b3b5
Compare
Co-authored-by: Matthew Draper <matthewd@github.com>
|
Hmm, @matthewd raised a good point. We don't want URLs that before just generated paths to suddenly start generating fully formed URLs. So need to sort that as well. |
aka47
left a comment
There was a problem hiding this comment.
use env APP_URL in comment
Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>
| delegate :tld_length, :tld_length=, :secure_protocol, :secure_protocol=, | ||
| :extract_domain, :extract_subdomain, :extract_subdomains, :url_for, | ||
| :full_url_for, :path_for, to: ActionDispatch::Http::URI |
There was a problem hiding this comment.
This is just a docs/api question, but I wonder what the purpose of having both a URL and URI class in the public domain, and if we just choose one (URL) because it's already public API than we should nodoc the URI class and keep the documentation for those public methods on the URL class (you can use # :method: extract_domain style rdoc notation).
There was a problem hiding this comment.
As for the public API, it will be less confusing to have one URL class. The idea is to move the rdoc comments for the delegated methods to the URL class from the URI class, and then make the URI class nodoc, right?
| delegate :tld_length, :tld_length=, :secure_protocol, :secure_protocol=, | |
| :extract_domain, :extract_subdomain, :extract_subdomains, :url_for, | |
| :full_url_for, :path_for, to: ActionDispatch::Http::URI | |
| # Returns the domain part of a host given the domain level. | |
| # :method: extract_domain | |
| # | |
| # # Top-level domain example | |
| # extract_domain('www.example.com', 1) # => "example.com" | |
| # # Second-level domain example | |
| # extract_domain('dev.www.example.co.uk', 2) # => "example.co.uk" | |
| delegate :tld_length, :tld_length=, :secure_protocol, :secure_protocol=, | |
| :extract_domain, :extract_subdomain, :extract_subdomains, :url_for, | |
| :full_url_for, :path_for, to: ActionDispatch::Http::URI |
| Rails.application.url = url | ||
| default_url_options = { host: url.host, protocol: url.scheme, port: url.port } | ||
| app.default_url_options = default_url_options if app.default_url_options.blank? | ||
| app.config.action_mailer.default_url_options = default_url_options if app.config.action_mailer.default_url_options.blank? |
There was a problem hiding this comment.
Does it matter if action_mailer is not included?
There was a problem hiding this comment.
| app.config.action_mailer.default_url_options = default_url_options if app.config.action_mailer.default_url_options.blank? | |
| if app.config.action_mailer.present? && app.config.action_mailer.default_url_options.blank? | |
| app.config.action_mailer.default_url_options = default_url_options | |
| end |
fix rebase issue
…y.yml.tt Co-authored-by: zzak <zzakscott@gmail.com>
|
We're going to move this to Rails 8.1. @matthewd is working on helping prepare some of the remaining work, but we're too close to the 8.0 release to get it all sorted in time. |
|
@matthewd Have you had a chance to look at this? Would love to see this land on main well in advance of 8.1 so we can really test it out. |
Fixes #39566
Other Information
The http/request.rb object is a complicated one - with around 6 different modules mixed in - Rack::Helpers, Rack::Env and others. I renamed ActionDispatch::Http::URL to ActionDispatch::Http::RequestURL as it is mainly building an URL out of the request object, for all the different settings and edge cases. Relying heavily on Rack in the background. Some of the methods, especially around constructing the port - need to stay part of RequestUrl as they are need to build the URL out of the request object and can not move to the URI class, unfortunately.
Once the url is build, we parse it and can work with it as an URI object.
Also - with the next release of Rack, Rack::Request::Env will be gone and that needs to be reflected in ActionDispatch::Request Class then.