简体   繁体   中英

Deploying multiple package.json Google Cloud

I am trying to modify this build: https://github.com/ebidel/try-puppeteer

I noticed that there are 2 package.json (and server.js) files.

  1. root ( https://github.com/ebidel/try-puppeteer/blob/master/package.json )

  2. backend ( https://github.com/ebidel/try-puppeteer/blob/master/backend/package.json )

Why do they deploy the backend and front end separately, with 2 express servers? Is this best practice? Design overkill?

What is the purpose of having two server.js files (or two servers) in one project?

Does it have a hierarchy system I overlooked?

Additionally, how do I deploy this project? from root of from backend?

You should deploy both, root is the frontend. From root :

npm run deploy-backend
npm run deploy-frontend

see package.json : https://github.com/ebidel/try-puppeteer/blob/master/package.json#L16

Why do they deploy the backend and front end separately, with 2 express servers? Is this best practice? Design overkill?

Compare two yaml files for front and back -ends:

https://github.com/ebidel/try-puppeteer/blob/master/app.yaml

automatic_scaling:
 min_num_instances: 1
 max_num_instances: 1

And

https://github.com/ebidel/try-puppeteer/blob/master/backend/app.yaml

automatic_scaling:
 min_num_instances: 1
 max_num_instances: 5

Author expects enough work for his backend to warrant scaling. In fact his frontend mostly serves static data, which doesn't consume anything at all and is too simple to fail.

Decoupling your application would imply that if backend is overloaded or crashed then front end will not suffer any downtime.

What is the purpose of having two server.js files (or two servers) in one project?

In this case those are two different applications with loose coupling: rather than connect on level of program they connect through network/Google Cloud App Engine. If you want to see it more clearly grep for ports 8080 and 8081 in the git repository. Many times “try-puppeteer/backend” would be a separate git repository with the hierarchy preserved and then downloade.

Does it have a hierarchy system I overlooked?

Frontend acts in as load balancer. Again look at ports 8081 and 8080 in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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