简体   繁体   中英

How to access backend from frontend on another localhost port?

We are making a web application where we have split up the frontend and backend into seperate projects. After setting up security with CAS we are unable to access the backend from frontend, getting 401 Unauthorized . Frontend is running at localhost:3000 , while the backend is running at localhost:8080 .

We would like to allow port 3000 to access port 8080 , but we don't know how, any clues?

If you are running on two separate projects for frontend and backend you need to write RESTAPIs. to access the backend instance you need to set up authentication, it might be CSRF or CORS. Please have a look at the cors document from spring boot https://spring.io/guides/gs/rest-service-cors/

it is for the 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. 

If you are trying to communicate with two different projects you need to write RESTAPIs, since you are using different port numbers, for security purpose you need to enable cross origin. refer this https://www.concretepage.com/spring-4/spring-4-rest-cors-integration-using-crossorigin-annotation-xml-filter-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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