I have an application with subdomains and I would like to be able to connect to a WebSocket of all of the subdomains when I add a subdomain to
cable/config.ru
ActionCable.server.config.allowed_request_origins = ["domain.com",
"sub1.domain.com", "sub1.domain.com"]
It works ok but how I can set alias for all subdomains somethink like this:
"[*.domain.com]"
Char " * "dosn't work.
Actioncable now supports regular expressions
Usage denoted below:
Action Cable will only accept requests from specified origins, which are passed to the server config as an array. The origins can be instances of strings or regular expressions, against which a check for match will be performed.
ActionCable.server.config.allowed_request_origins = ['http://rubyonrails.com', /http:\/\/ruby.*/]
You can use regex for this case. In environments files (production and development) use this:
config.action_cable.allowed_request_origins = [/(?:^(http|https):\/\/)?(?:([^.]+)\.)?#{ENV["domain"]}/]
As the ENV["domain"] the domain that the application runs in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With