繁体   English   中英

如何从另一个本地主机端口上的前端访问后端?

[英]How to access backend from frontend on another localhost port?

我们正在制作一个Web应用程序,在其中将前端和后端划分为单独的项目。 使用CAS设置安全性后,我们无法从前端访问后端,从而获得401 Unauthorized 前端运行在localhost:3000 ,而后端运行在localhost:8080

我们想允许端口3000访问端口8080 ,但我们不知道如何,有什么线索?

如果您在前端和后端的两个不同项目上运行,则需要编写RESTAPI。 要访问需要设置身份验证的后端实例,可能是CSRF或CORS。 请查看Spring Boot https://spring.io/guides/gs/rest-service-cors/中的cors文档

它用于csrf https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html

Front end : localhost:3000/yourfilename.html

**Front end** default port of xamp port is 80. So We re basically use 
localhost/yourfilename.html. But Here used 3000 port. so We should call port 
number with that url 

**Back end** : localhost:8080/apiurl
It is ordinary port of backend. 

如果尝试与两个不同的项目进行通信,则由于要使用不同的端口号,因此需要编写RESTAPI,出于安全目的,您需要启用跨源。 请参阅此https://www.concretepage.com/spring-4/spring-4-rest-cors-integration-using-crossorigin-annotation-xml-filter-example

暂无
暂无

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

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