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

config.action_cable.url in development is being overwritten somewhere #115

Closed
tambakoo opened this issue Feb 12, 2020 · 5 comments
Closed

Comments

@tambakoo
Copy link

Environment
ruby 2.5.0p0
Rails 6.0.0.rc2
AnyCable v0.6.4
anycable-rails (0.6.5)
grpc (1.27.0)

I set up anycable using the official documentation but I kept getting a
ActionController::RoutingError (No route matches [GET] "/cable"):. The url being knocked on was ws://localhost:3000/cable while the anycable-go websocket server is running on port 3334.
I use webpacker on this app.
This routing error is only fixed when in the app/javascript/channels/consumer.js I use

import { createConsumer } from "@rails/actioncable"
export default createConsumer('ws://localhost:3334/cable')

that is, explicitly declare the url while creating the consumer.

It does not matter if I remove the config.action_cable_url from development.rb which is very weird. This is clearly a case of overwritten configuration.

This error was not resolved by #88 or #41.
Does this look like a webpacker problem ? Please tell me what files will be relevant to debug this.

@tambakoo tambakoo changed the title config.action_cable.url in development is being overwritten somewhere config.action_cable.url in development is being overwritten somewhere Feb 12, 2020
@palkan
Copy link
Member

palkan commented Feb 12, 2020

Hey!

Do you use the action_cable_meta_tag helper in your HTML? And if yes, is it called before the JS script is loaded?

Action Cable uses meta tags (set by action_cable_meta_tag) to get the value of config.action_cable.url (NOTE: it is action_cable.url not action_cable_url).

@tambakoo
Copy link
Author

tambakoo commented Feb 12, 2020

Hey!

Do you use the action_cable_meta_tag helper in your HTML? And if yes, is it called before the JS script is loaded?

Action Cable uses meta tags (set by action_cable_meta_tag) to get the value of config.action_cable.url (NOTE: it is action_cable.url not action_cable_url).

  1. This is how my application.html.erb looks like -
<!DOCTYPE html>
<html>
  <head>
    <title>CapApi</title>
    <%= action_cable_meta_tag %>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>
  1. My bad, I meant action_cable.url. It's written correctly on the code.

@palkan
Copy link
Member

palkan commented Feb 12, 2020

Thanks!

And what do you see in the rendered HTML then? Does it contain the valid link (localhost:3334)?

@tambakoo
Copy link
Author

Thanks!

And what do you see in the rendered HTML then? Does it contain the valid link (localhost:3334)?

yes there is a <meta name="action-cable-url" content="ws://localhost:3334/cable"> on the rendered HTML.

@palkan
Copy link
Member

palkan commented Feb 13, 2020

The only suggestion is to debug the JS createConsumer function and see where it gets the URL from if it’s not provided. It should be from the meta tag 🤷🏻‍♂️

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

No branches or pull requests

2 participants