简体   繁体   English

Laravel + Angular 从外部网络访问被 CORS 阻止

[英]Laravel + Angular accessing from outside network blocked by CORS

All questions i have seen on this topic have been on a local network, but i haven't seen any that answer it for an outside the network connection.我在这个主题上看到的所有问题都在本地网络上,但我还没有看到任何可以回答外部网络连接的问题。

I have a laravel backend and a Angular (and ionic) frontend.我有一个 laravel 后端和一个 Angular(和离子)前端。 If i host them on 192.168.xx:XXXX and i access them from within my network everything is fine, and they do all HTTP requests perfectly and there are no CORS errors.如果我将它们托管在 192.168.xx:XXXX 上并且我从我的网络中访问它们,一切都很好,它们可以完美地完成所有 HTTP 请求,并且没有 CORS 错误。

The problem comes when i try to access use the applications from outside the network.当我尝试从网络外部访问使用应用程序时,问题就来了。 I have setup the port forwarding needed to access the application from the outside, so if i access from any browser outside the network to xxxx(my public IP):XXXX(port which its running on) i have access to the application, both the backend and the frontend.我已经设置了从外部访问应用程序所需的端口转发,所以如果我从网络外部的任何浏览器访问 xxxx(我的公共 IP):XXXX(其运行的端口)我可以访问应用程序,两者后端和前端。

But if i try any action within the application, for example a login,(keep in mind i changed the request IP to the appropriate public IP in these methods ) i get a CORS error:但是如果我在应用程序中尝试任何操作,例如登录,(请记住,我在这些方法中将请求 IP 更改为适当的公共 IP)我得到一个 Z5A8FEFF0B4BDE3EEC9244B76023B79DZ 错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://(My public IP)/_connect_hashaudit_/frame/public/test?hash=6918596600873537056&id=34686533401. (Reason: CORS request did not succeed).

These are my CORS settings in my laravel app:这些是我的 laravel 应用程序中的 CORS 设置:

'paths' => ['*'], //Set to all to avoid CORS errors when accessing the server during development

'allowed_methods' => ['*'],

'allowed_origins' => ['*'],

'allowed_origins_patterns' => ['*'],

'allowed_headers' => ['*'],

'exposed_headers' => ['*'],

'max_age' => 0,

'supports_credentials' => false,

I am running them on XAMPP Apache我在 XAMPP Apache 上运行它们

I understand how these servers are intended for development use only, but i would like if i could demonstrate these apps remotely.我了解这些服务器如何仅用于开发用途,但我希望我可以远程演示这些应用程序。 I'm not going to leave these servers running.我不会让这些服务器继续运行。 Is there any way to solve this, or run these servers on something else to get around this?有没有办法解决这个问题,或者在其他东西上运行这些服务器来解决这个问题?

As @sideshowbaker mentioned the CORS error was just a symptom of another error.正如@sideshowbaker 提到的,CORS 错误只是另一个错误的症状。 It turns out that XAMPP doesn't allow you to do this unless you run it in administrator mode事实证明 XAMPP 不允许你这样做,除非你在管理员模式下运行它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM