7

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.

Wazery
  • 15,394
  • 19
  • 63
  • 95
Adrian
  • 532
  • 1
  • 7
  • 16
  • Just out of curiosity, do you use ActionCable on production level? Or you are just playing with it? – Wazery Nov 17 '15 at 00:36

3 Answers3

7

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.*/]

David Kuhta
  • 742
  • 7
  • 13
2

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.

Pedro Samuel
  • 121
  • 4
0

[OUTDATED ANSWER]

It seems that something like this is not implemented yet from the current implementation of ActionCable on its official repo on GitHub.

Wazery
  • 15,394
  • 19
  • 63
  • 95