0

Please find my below use case:

There is a backend web service developed in Java running at http://localhost:8080 and an angular UI application running at http://localhost:4200. Now my requirement is on successful login, Backend service sets cookies in the response object.

After that, all subsequent requests from UI to the backend service should be content set cookies by the backend service.

Issue:

As the backend is running on a different port, UI is not able to read the cookies and all subsequent requests from UI to the backend is not containing cookies.

Could anyone please help me with this issue?

3
  • so you set the cookie in the backend and the Angular UI doesn't see it? Commented Jul 1, 2023 at 4:00
  • Yes, you are right. Commented Jul 1, 2023 at 4:03
  • show your backend code maybe? and show the front end network call also. Commented Jul 1, 2023 at 19:48

1 Answer 1

0

For production you should use nginx or Apache in order to work on the same port.

For development you can define a path for backend, for example /api/ and tell Angular redirect all requests to this path to your backend server(on another port) this look like

{
  "/api": {
    "target": "http://localhost:8080",
    "secure": false,
    "changeOrigin": true
  }
}

Official guide https://angular.io/guide/build#proxying-to-a-backend-server

Another one https://juristr.com/blog/2016/11/configure-proxy-api-angular-cli/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.