简体   繁体   English

在AWS上部署React + Express

[英]Deploy React + Express on AWS

I'm quite new to AWS and web development so please bear me if my questions look silly. 我对AWS和Web开发非常陌生,所以如果我的问题看起来很傻,请多多包涵。

  1. I have an Express service deployed via AWS codestar. 我有一个通过AWS Codestar部署的Express服务。 the service address is myservice.ap-southeast-2.elasticbeanstalk.com 服务地址是myservice.ap-southeast-2.elasticbeanstalk.com
  2. A react app is deployed on S3 bucket. React应用程序已部署在S3存储桶上。

My question is, how can I access (like make ajax call) to Express service inside React app in production enviroment? 我的问题是,如何在生产环境中的React应用程序内访问(如进行ajax调用)Express服务? Just append any ajax call with the service address? 只需将任何ajax调用附加到服务地址?

The s3 bucket React app is in was created by AWS codestar, does that mean the React and Express are on the same machine? s3存储桶中的React应用程序是由AWS Codestar创建的,是否意味着React和Express在同一台机器上? I mean if they are on same machine the ajax call will be faster, right? 我的意思是,如果它们在同一台机器上,ajax调用会更快,对吗?

Another option is, since Codestar instantiated an EC2, I can deploy the React into the EC2. 另一个选择是,由于Codestar实例化了EC2,因此我可以将React部署到EC2中。 So that Express on EC2 serves all API requests but for static files and index.html Express directly returns the deployed React assets. 因此,EC2上的Express可以处理所有API请求,但仅用于静态文件,而index.html Express可以直接返回已部署的React资产。

Anyone knows which solution is better? 谁知道哪个解决方案更好?

Well, the best solution is the one that fits better your needs. 好吧,最好的解决方案是最适合您需求的解决方案。 For example, if you would need server side rendering, it would be better to add your React application to the EC2 that is currently holding your express app; 例如,如果您需要服务器端渲染,最好将您的React应用程序添加到当前拥有您的Express应用程序的EC2中。 aside from that, I would continue using S3 bucket for your compiled React application. 除此之外, 我将继续对已编译的React应用程序使用S3存储桶 If your concern is about performance/latency, you can use AWS Cloudfront to improve those timings. 如果您担心性能/延迟,可以使用AWS Cloudfront改善这些时间安排。

To access your Express app, you call your application's IP (under AWS Console > EC2 > your instance > IPv4 Public IP or Public DNS (IPv4) as your host in the ajax call. 要访问Express应用,请在ajax调用中将应用的IP(在AWS控制台> EC2>您的实例> IPv4公用IP或公用DNS(IPv4)下)作为主机。

Just to clarify, your EC2 and S3 bucket are in different machines. 为了澄清起见,您的EC2和S3存储桶位于不同的计算机中。

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

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