構成
- Docker
- Rails 6 (APIモード)
- Nuxt.js
エラーになった
Nuxt 側から Axios でRails のAPIを呼び出すぞ!
と今までと同じように以下の設定をしたけど
/.env
API_BASE_URL=http://host.docker.internal:8000
nuxt.config.js
axios: {
baseURL: process.env.API_BASE_URL
},
こんなエラーが出てしまった🤔
Blocked host: host.docker.internal
To allow requests to host.docker.internal, add the following to your environment configuration:
config.hosts << "host.docker.internal"
解決法
色合い的に Railsのエラーっぽいなーと調べると、
Rails 6 で新たに追加された ActionDispatch::HostAuthorization
というミドルウェアで、
許可していないホスト名宛のアクセスは拒否されるようになったみたい。
( 0.0.0.0
や localhost
はデフォルトで許可されている)
Guard against DNS rebinding attacks by permitting hosts
https://github.com/rails/rails/pull/33145
エラーメッセージの通り、 config に config.hosts
を追記して解決!
config/environments/development.rb
Rails.application.configure do
...
config.hosts << "host.docker.internal"
end