Rails config.hosts

Hello, I tried to add this to config/environments/production.rb:
config.hosts << ENV['RAILWAY_PUBLIC_DOMAIN']
config.hosts << ENV['RAILWAY_PUBLIC_DOMAIN']
But I'm still getting an error on https://rails-production-b7c8.up.railway.app/
To allow requests to rails-production-b7c8.up.railway.app make sure it is a valid hostname (containing only numbers, letters, dashes and dots), then add the following to your environment configuration:
config.hosts << "rails-production-b7c8.up.railway.app"
To allow requests to rails-production-b7c8.up.railway.app make sure it is a valid hostname (containing only numbers, letters, dashes and dots), then add the following to your environment configuration:
config.hosts << "rails-production-b7c8.up.railway.app"
I don't want to hard code in the Railway host which is why I tried the provided Railway domain.
13 Replies
Percy
Percy14mo ago
Project ID: 467582c5-6f4d-4ae0-a734-6605d39f5edc
paulmwatson
paulmwatsonOP14mo ago
Project ID: 467582c5-6f4d-4ae0-a734-6605d39f5edc
Brody
Brody14mo ago
are you building with dockerfile?
paulmwatson
paulmwatsonOP14mo ago
I used the Railway template via the website https://github.com/railwayapp-templates/ruby-rails
Brody
Brody14mo ago
can you print out the value of that environment variable just as a sanity check?
paulmwatson
paulmwatsonOP14mo ago
Thanks for the help. I tried railway run bash and printenv shows it as the expected value RAILWAY_PUBLIC_DOMAIN=rails-production-b7c8.up.railway.app but I can't run rails c to confirm it in the Rails app env.
Brody
Brody14mo ago
print it out from within your code on railway please
paulmwatson
paulmwatsonOP14mo ago
I don't know how to do that it's runtime code though isn't it? this is the code being deployed though https://github.com/paulmwatson/railsway/blob/main/config/environments/production.rb#L5
Brody
Brody14mo ago
you arent aware of a way to log a value?
paulmwatson
paulmwatsonOP14mo ago
I can do that yes, hoping to fix this without a redeploy to log values though. I'll check now. hah I added logger.debug "config.hosts: #{config.hosts}" but nothing new appeared in Observability, just the same [ActionDispatch::HostAuthorization::DefaultResponseApp] Blocked host: rails-production-b7c8.up.railway.app. I'll park this for now and come back at it tomorrow. Thanks Brody.
Brody
Brody14mo ago
can you log the RAILWAY_PUBLIC_DOMAIN env var?
paulmwatson
paulmwatsonOP14mo ago
I added logger.info "ENV['RAILWAY_PUBLIC_DOMAIN']: #{ENV['RAILWAY_PUBLIC_DOMAIN']}" but still nothing appearing in logs
No description
Brody
Brody14mo ago
are you writing to stdout without a buffer?
Want results from more Discord servers?
Add your server