0

I am working with Rails 5 and Action Cable, trying to configure the allowed request origins option. I can't quite figure out how to generate the appropriate regex for what I need:

http://*.ENV["APP_HOSTNAME"]:3000

Basically, I need to be able to provide a rails environment variable to specify the host and have wildcard subdomains. I've tried a variety of expressions and can't quite get it. Can someone please help me with this?

Lorenz
  • 737
  • 1
  • 7
  • 26

1 Answers1

1
Rails.application.config.action_cable.allowed_request_origins = [
  %r{\Ahttps?://[^./]+\.#{ ENV['APP_HOSTNAME'].gsub('.', '\.') }:3000\z},
  %r{\Ahttps?://[^./]+\.#{ ENV['APP_HOSTNAME'].gsub('.', '\.') }:3000/}
]

This will allow only for level 1 subdomains. I'm not 100% sure second regexp is needed.

graudeejs
  • 349
  • 1
  • 6