Skip to content
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

New Feature: Protocol support #131

Closed

Conversation

andrewhavens
Copy link

New Features:

  • Adds protocol support when generating URL helpers, for routes with specific protocol specified.
  • Adds support for "protocol relative" base URL value in :url_links config.

Changes:

  • generate_url_link no longer validates that the :url_links config value contains the protocol.

This PR fixes #127.

let(:_options) { { :url_links => "//example.com" } }
it "should generate url links with correct protocol" do
expect(evaljs("Routes.new_inbox_url()")).to eq("//example.com#{routes.new_inbox_path}")
expect(evaljs("Routes.new_session_url()")).to eq("//example.com#{routes.new_session_path}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand if the url_links is abstract from protocol than protocol route option is ignored, correct? I don't think this is right.

new_session route forces protocol to be https and it can only be ignored when url_links specified protocol explicitly.

So I think that //example.com and example.com should work in the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @bogdan is right. //example.com use protocol from which web page was loaded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bogdan Depends on how you think of it. Some people might expect a protocol relative base URI to stay protocol relative since it would be used in HTML. If you are on https and you want to stay on https then using protocol relative URI would work. Pre-generating the routes would have no way of knowing if you were on http or https. We could add some JavaScript to detect that when the JavaScript function is called, but I don't think that is the best way to do it. I designed this to support backwards compatibility (minor version bump) while providing the ability to add a specific protocol at runtime, but I think it would be better to not support protocol relative base URIs at all, add a default_host config, and have the routes definition be the authority on which protocol/host to use. This would require a major version bump since it would change the behavior/expectations of the config values, but I think it would be better in the long run. If you agree, I will make the changes to this pull request.

@andrewhavens
Copy link
Author

@bogdan @le0pard I just realized that js-routes already provides a default_url_options config option. I think we could add support for the :host option to the existing hash rather than adding a new default_host option. This would mirror the Rails behavior. Do you agree with this?

Also, do you agree that the config/routes.rb file should be the authority on which host/protocol to use when generating URLs?

@andrewhavens
Copy link
Author

I'm going to close this PR since it has been superseded by #132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support protocol option in route generation
3 participants