Help us understand the problem. What is going on with this article?

LaravelでAPIサーバ作ってる時にsafariでCORSがうまくいかなかった

More than 1 year has passed since last update.

背景

Vue.jsでaxios使って外部ドメインのAPIを叩くように実装していて、
laravel(ver 5.7)でAPIサーバを作ってCORSの対応をしていました。
ChromeやFirefoxではうまくいっていたんですけど、safariではエラーが発生、、、

Origin http://... is not allowed by Access-Control-Allow-Origin.

試したこと

CORSの対応としては下記を参考にしていました。
・[https://hiroslog.com/post/67]
・[http://kayakuguri.github.io/blog/2017/06/19/larave-cors/]

結果、safari(ver 9.1)のみCORSに必要なヘッダー情報が付与されず、、、

対応

暫定として、.htaccessにヘッダー情報を書いて対応。

.htaccess
<IfModule mod_headers.c>    
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Headers "*"
    Header set Access-Control-Allow-Headers "X-CSRF-TOKEN,Content-Type,Origin,Authorization,Accept,X-Requested-With"
</IfModule>

*は適宜変更が必要

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした