Angular和Go服务器在同一端口上

I'm creating a web project where I am intergrating both Angular, for the frontend, and Go for the backend. With the backend I need to use the HTTP web server in order to display data using a RESTAPI, however, my issue is that I cannot run both servers on port 80 (which is basic knowledge). But I was wondering if there was a work around to this. I prefix all my backend pages with the prefix /backend/ (so for example https://example.com/backend/auth), therefore there shouldn't be any file/page collisions taking place.

One of the main reasons I am trying to accomplish this is because I want to set the cookies for the site in the backend as it'd be far easier and less complex for my situation, but I'm not sure how to because unless they are on the same port they would not share the same cookies.

Any help would be greatly appreciated, thank you.

  1. If both frontend and backend are on same server (but different ports), will they share cookies?
    Yes, they will, check this SO answer. As per latest RFC, cookies for a given host are shared across all the ports on that host.

  2. How to verify the user account from frontend to backend?
    a) If using social authentication, check this SO question, and this great article. In short, your frontend gets the access token from OAuth and passes it to backend which can call the OAuth provider (e.g. Graph API) to verify the access token. Create a new session and pass to frontend.

    b) If NOT using social authentication, your users will enter their username/password which the frontend will receive. It can pass those credentials to backend, which will then generate a session and pass to frontend.

    c) In both a) and b), the frontend is creating cookie with session information given by backend. On every user request frontend would receive the cookie, hence the frontend would have to validate session with backend on every user request.

    d) A better way is to replace cookies with JWT Tokens but the flow would remain the same.