dongpao1905 2017-08-21 00:57
浏览 105

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条回答 默认 最新

  • doushifang4382 2017-11-26 16:42
    关注
    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.
    评论

报告相同问题?

悬赏问题

  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页