LoginSignup
4
2

More than 5 years have passed since last update.

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

Posted at

背景

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>

*は適宜変更が必要

4
2
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
4
2