0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails で別オリジンのリクエスト with Cookie を受け付ける

Posted at

別ポートの localhost で立ち上げた Nuxt (フロントコード) から Rails 側で開いた API へのリクエストが CORS 制約に引っかかったので対処。

gem を追加。

gem 'rack-cors'

以下を追記。

config/application.rb
config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'localhost:8000' # ポート番号はよしなに
    resource "*",
      headers: :any,
      methods: [:get, :post, :options, :head],
      credentials: true
  end
end

credentials: true をつけないと Cookie を扱えないようです。

おしまい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?