*套件fruitcake/laravel-cors設定API允許跨網域請求:
1.安裝套件fruitcake/laravel-cors
(laravel 8 預設就有安裝,不須再安裝)
composer require fruitcake/laravel-cors
2.產生config檔:
(產生的檔案在 config/cors.php)
(laravel 8 預設就有,不須再產生)
php artisan vendor:publish --tag="cors"
3.使用fruitcake/laravel-cors
*設定 app/Http/Kernel.php
(laravel 8 預設就有設定,不須再設定)
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
...
];
*設定 config/cors.php
// paths 加入 'oauth/*',才能"跨網域"請求 passport 的 access_token
'paths' => ['api/*', 'oauth/*', 'sanctum/csrf-cookie'],
---------------------------------
參考資料:
fruitcake/laravel-cors
https://github.com/fruitcake/laravel-cors
沒有留言:
張貼留言