LoginSignup
14
17

More than 5 years have passed since last update.

Vagrantでサーバー立ててActionCableを試してる時にRequest origin not allowedがでて辛い

Posted at

rails5のベータ出ましたね。試したくなったので触ってたらハマったのでメモ。

結論

下記見ると一発だった。
https://github.com/rails/rails/tree/master/actioncable#allowed-request-origins

private_ipを設定していたから、つながらなかったんですね。。。

本文
By default, Action Cable allows all requests from localhost:3000 when running in the development environment.
意訳
environmentがdevelopmentの時は、localhost:3000からのすべての要求を許可します.

エラー文

ちょっと加工した
Started GET "/" [****] for 192.168.33.1 at 2015-12-24 +Request origin not allowed: http://192.168.33.10:3000

対応した方法

サンプルなのでどこからでも要求を許可するように、initializersにaction_cableの設定書きました。

config/initializers/action_cable.rb
# どっからでも許可するようにする
ActionCable.server.config.disable_request_forgery_protection = true

多分こうした方がいいかも

試してないのであれですが、nginxとか使っていい感じに中継してもらったりすると上記の設定必要なくなるかもしれないです。

14
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
17