React frontend and Node backend on GCP App Engine: API routes not working after deployment

Help needed with GCP App Engine deployment!

I’ve got a React frontend with a Node backend running smoothly on my local machine. But after pushing it to Google Cloud Platform, I’m hitting a snag.

The React part is fine, but when I try to use the /api/mail/send route for Nodemailer, it’s a no-go. I’m getting either a 404 (can’t find it) or a 500 error, depending on my yaml setup.

I’ve tried tweaking the app.yaml file, but no luck so far. My package.json looks okay, and the server.js seems to be set up right.

Any ideas what could be causing this? Maybe I’m missing something in the deployment process? Or is there a GCP-specific thing I need to do for the API routes?

I’m stumped and could really use some expert advice. Thanks in advance for any help!

hey, i needed to check my app.yaml and server port too. are u sure the api route is defined properly in server.js? i had similar issues and resolved them by adjusting process.env.PORT and using gcloud deploy correctly. what else might be missing?

yo, have u tried checking ur server’s logs? sometimes the issue isn’t obvious from just looking at the code. in gcp, u can use ‘gcloud app logs tail’ to see whats happening. also, make sure ur api routes r defined before any catchall routes in ur express app. those sneaky 404s can be caused by route order too!

Having dealt with similar issues, I can suggest a few things to check. First, ensure your server.js is correctly handling the port assignment. Use const port = process.env.PORT || 8080; to allow GCP to assign the port dynamically. Next, review your app.yaml file. It should include a handler for API routes, like:

- url: /api/.*
  script: auto

Also, double-check that your API routes are defined correctly in your Express app. Sometimes, the issue lies in how routes are structured. Lastly, when deploying, use gcloud app deploy and ensure your project ID is set correctly. If these steps don’t resolve the issue, you might need to look into GCP’s logging feature to get more detailed error information.