跨域访问,Access-Control-Allow-Origin

JWT由于没有使用Cookies,Cross-Origin Resource Sharing (CORS) ,跨域的资源访问不会成为问题。

augular6在本地执行,访问 http://localhost:4200 时出现:

Failed to load http://www.empirecclt.com.au/public/api/heroes: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

一、第一种解决方案:

https://github.com/barryvdh/laravel-cors

在  lavarel  所在的工程下安装

composer require barryvdh/laravel-cors

使用:找到  app -> Http -> Kernel.php 添加

'api' => [

     ...

     \Barryvdh\Cors\HandleCors::class,

],

二、第二种解决方案:

chrome浏览器安装 Allow-Control-Allow-Origin: * 插件

三、第三种解决方案:

分析原理,ng build,将生成的dist文件夹中的文件上传到服务器public文件夹后,不会出现跨域问题

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。