VUE SPA和Laravel API的CORS问题

时间:2020-01-26 09:13:14

标签: laravel vue.js cors

我有一个使用VueJS SPA和Laravel API作为后端创建的项目。

为避免CORS问题,我使用了Laravel软件包barryvdh/laravel-cors,并进行了正确配置。

这是我的Laravel项目中的cors.php代码:

<?php 
return [
    'paths' => ['api/*'],
    'allowed_methods' => ['*'],
    'allowed_origins' => ['*'],
    'allowed_origins_patterns' => [],
    'allowed_headers' => ['*'],
    'exposed_headers' => false,
    'max_age' => false,
    'supports_credentials' => false,
];

但是我在前端VueJS App中收到以下错误。随附的屏幕截图:

错误文字

Access to XMLHttpRequest at 'https://anysaleapi.alphatech.com.np/api/user/' from origin 'https://anysale.alphatech.com.np' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

CORS error image

这是我的响应标题:

Access-Control-Allow-Origin: https://anysale.alphatech.com.np
Cache-Control: no-cache, private
Connection: Keep-Alive
Content-Type: application/json
Date: Sun, 26 Jan 2020 08:00:37 GMT
Keep-Alive: timeout=5, max=99
Server: Apache
Transfer-Encoding: chunked
Vary: Origin
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58

0 个答案:

没有答案