简体   繁体   English

REST API和Web客户端的服务器配置

[英]Server configuration for REST API and web client

I developed a REST API with go (golang), and now I want to design my web frontend. 我用go(golang)开发了一个REST API,现在我想设计我的web前端。 I don't know how can I separate frontend from backend. 我不知道如何将前端与后端分开。

I think that I have three choices: 我想我有三个选择:

1- Run REST API on one server and the frontend website on another server. 1-在一台服务器上运行REST API,在另一台服务器上运行前端网站。

2- Run REST API and frontend website on the same server, but on different ports. 2-在同一台服务器上运行REST API和前端网站,但在不同的端口上运行。 For example run REST on port 8080 and frontend website on port 80. 例如,在端口8080上运行REST,在端口80上运行前端网站。

3- Run Both on the same server and the same port, but use different URL paths (or subdomains) for each one. 3-在同一服务器和同一端口上运行两者,但为每个端口使用不同的URL路径(或子域)。

As I don't know about this stuff, please tell me which one is true or best solution. 由于我不知道这些东西,请告诉我哪一个是真的或最好的解决方案。 Or is there any other solution? 或者还有其他解决方案吗? Does it matter how big my website is? 我的网站有多大是否重要?

Either the first or second options will be mostly the same for you to set up and develop with. 第一个或第二个选项将与您进行设置和开发大致相同。 So you don't lose or gain anything from that perspective, the only deciding factor is your resources and how you expect your backend to be used in the future. 因此,您不会从这个角度失去或获得任何东西,唯一的决定因素是您的资源以及您希望将来如何使用您的后端。

Currently, if you only have one application/frontend calling on the API, having them be on the same server will be the better option since it will have a marginally increased performance compared to the second option. 目前,如果您只有一个应用程序/前端调用API,将它们放在同一台服务器上将是更好的选择,因为与第二个选项相比,它的性能会略有提高。

But, since you chose a RESTful design for your backend, you might want to reuse it for more applications in the future, and if you expect that the increase in calls to the API will start to use up the server resources, then your frontend might suffer from it and then you should consider relocating the backend to a different server. 但是,由于您为后端选择了RESTful设计,因此您可能希望将来将其重用于更多应用程序,如果您希望API调用的增加将开始耗尽服务器资源,那么您的前端可能会遭受它,然后你应该考虑将后端重新定位到不同的服务器。

The whole microservices, RESTful backend design "pattern" was created to decouple the front and back for better scaling, but that might not be necessary for everyone, you have to estimate the amount of use your application will realistically have and think if you might actually reuse the API elsewhere (or if you want to offer the API for others or not). 整个微服务,RESTful后端设计“模式”是为了更好地扩展前后分离而创建的,但对于每个人来说可能不是必需的,你必须估计你的应用程序实际拥有的使用量,并考虑你是否真的在其他地方重用API(或者如果您想为其他人提供API)。

In the end, if the first and second option present a similar amount of investment for you at the moment, go for the first one, if not, just keep both front and back on the same server and if in the future you realize you need to scale out, you can just relocate the API to a different server/servers. 最后,如果第一个和第二个选项目前为您提供类似的投资,请转到第一个,如果没有,只需将正面和背面保持在同一台服务器上,如果将来您意识到需要要向外扩展,您只需将API重定位到其他服务器/服务器即可。

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

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