0

I have an app hosted on Heroku, using Redis Cloud and ActionCable. Locally everything works but on Heroku the user is redirected to a localhost address after a form is submitted. I have tried most of the advice listed here (apart from resque settings since resque gem is not installed): Redis tries to connect to localhost on Heroku instead of REDIS_URL

Redis Cloud was added with

heroku addons:create rediscloud:30

This is in my cable.yml, I have commented out two other solutions that I tried that also did not work (in my actual code, redis url is set to the actual address rather than xxx999)

production:
  adapter: redis
  # url: <%= ENV.fetch('REDISCLOUD_URL') %>
  # url: <%= ENV.fetch("REDISCLOUD_URL") { "redis://localhost:6379/1" } %>
  url: <%= ENV.fetch("REDISCLOUD_URL") { "redis://default:xxx999@redis-13674.c77.eu-west-1-1.ec2.cloud.redislabs.com:13674" } %>
  channel_prefix: art--collabs_production

In redis.rb:

if ENV["REDISCLOUD_URL"]
  $redis = Redis.new(url: ENV["REDISCLOUD_URL"])
end

In production.rb I have the following (again, the commented out code has been tried and also failed)

config.action_cable.url = "ws://www.artcollabs.net/cable"
config.action_cable.allowed_request_origins = [ "http://www.artcollabs.net", "https://www.artcollabs.net" ]

# config.cache_store = :redis_cache_store, { url: ENV.fetch("REDISCLOUD_URL", "redis://localhost:6379/1") }
config.cache_store = :redis_cache_store, { url: ENV.fetch("REDISCLOUD_URL", "redis://default:xxx999@redis-13674.c77.eu-west-1-1.ec2.cloud.redislabs.com:13674") }

Any suggestions on how to solve this?

пaean
  • 61
  • 8
  • Why not use `heroku config:set REDISCLOUD_URL=redis://default:xxx999@redis-13674.c77.eu-west-1-1.ec2.cloud.redislabs.com:13674` instead of hardcoding the URL as a default in your configuration files? – max May 13 '21 at 10:42
  • It is already set to this address in heroku config. The only reason I hardcoded it is because using `redis://localhost:6379/1` or `redis://localhost:6379/0` in its place did not work – пaean May 13 '21 at 10:49
  • If you have set `ENV['REDISCLOUD_URL']` then your default will never be used. Thats how defaults work. – max May 13 '21 at 10:51
  • Do you have any idea why it still redirects to localhost? – пaean May 13 '21 at 10:54
  • What does `heroku config:get REDISCLOUD_URL` tell you? – max May 13 '21 at 10:56
  • It gives me the same address that I hardcoded – пaean May 13 '21 at 10:58

0 Answers0