Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
单页应用
|
185
刚开始使用
React
的时候,基本上可以忽略整个应用范围错综复杂的状态管理,但是很快,
你会认识到需要更有条理的方式来管理状态。到了那个时候,就会希望深入研究其中一些
候选技术,并找出认同的那个。
16.4.7
 部署选择
目前为止,我们一直在使用
CRA
内建的开发服务器。它的确是开发时的最好选择,推荐
你使用。然而,到了部署的时候,它就不是合适的选择了。幸运的是,
CRA
本身包含着构
建脚本,可以创建为生产而优化的资源包,然后你就有很多的选择了。当你做好创建部署
包的准备时,只需运行
yarn build
,就会创建出一个
build
目录。
build
目录下的资源文件
都是静态的,可以部署到任何地方。
我目前的部署选择是把
CRA
构建
放到
AWS S3
的一个
bucket
上,并启用静态网站托管。
这当然不是唯一的选择,每个主要的云服务提供商和
CDN
都提供类似的服务。
在这个构建配置中,我们必须创建路由,以便将
API
调用路由到你的
Express
服务器
,并
且从
CDN
访问到静态资源
。就我的
AWS
部署来说,我使用了
AWS
的
CloudFront
来实施
这个路由,静态资源从前面提到的
S3
的
bucket
上提供
,而
API
请求会被路由到一个
EC2
实例或是
Lambda
上。
另一个选择是让
Express
把所有这些事情都做了
。这样做的优势是,可以把你的整个应用
都合并进一个服务器里,这样部署起来简单,管理也容易。从伸缩性或性能的角度来说,
这么做可能不会很理想,但对于小型的应用来说是一个合理的选择。
要从
Express
提供整个应用的服务 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099