简体   繁体   中英

Structuring and deploying node frontend and backend to Google App Engine

I'm working on a React project with two node apps:

  • Client : Frontend code using React JS and Axios for making requests to my backend service.
  • API : Backend service using Mongoose to connect to MongoDB and Express for handling restful requests.

I had a couple questions:

  • Is it a best practice to create separate node applications like this for frontend and backend? I want to confirm this is a good setup.
  • I've had some difficulties in deploying this to Google App Engine and could use some pointers.

What I've currently done:

  • Added an api.yaml to my API service subdirectory.
  • Deployed using gcloud app deploy client/app.yaml api/api.yaml which deploys two services (frontend and backend).

Is this a good approach?

If so, the challenge I'm now facing is that my API service is deployed to a subdomain and requests from my frontend are failing. Locally I am using the proxy value to proxy requests to my backend port on localhost, but I'm not sure how to modify my app to dynamically make backend requests to the correct subdomain when in the production environment (I also think CORS comes into play).

You need a dispatch.yaml file. The dispatch.yaml allows you to override routing rules. You can use the dispatch.yaml to send incoming requests to a specific service (formerly known as modules) based on the path or hostname in the URL.

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