Deploying to GCP App Engine with React Frontend and Node backend not able to hit api routes on deployed version by works locally

Viewed 725

I have deployed my site to google cloud platform and the react(static) part is working fine, but anytime I go to /api/mail/send to use nodemailer I either get a 404 error saying it cant be found or with some configurations in the yaml file I just a 500 error.. below is my yaml, package.json and server.js files

App.yaml

runtime: nodejs12
env: standard
basic_scaling:
  max_instances: 5
  idle_timeout: 5m
handlers:
  - url: /api/.*
    secure: always
    script: auto
  - url: /
    static_files: client/build/index.html
    upload: client/build/index.html
    secure: always
  - url: /
    static_dir: client/build
    secure: always

Package.json

{
  "name": "mern",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "dev": "concurrently \"nodemon --ignore 'client/*'\" \"npm run client\"",
    "client": "cd client && npm run start",
    "install": "cd client && npm install",
    "build": "cd client && npm run build"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer": "^9.8.6",
    "concurrently": "^5.3.0",
    "husky": "^4.2.5",
    "postcss-cli": "^7.1.1",
    "tailwindcss": "^1.6.2"
  },
  "dependencies": {
    "if-env": "^1.0.4",
    "axios": "^0.19.2",
    "body-parser": "^1.19.0",
    "classnames": "^2.2.6",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "morgan": "^1.10.0",
    "nodemailer": "^6.4.11"
  }
}

server.js

require('dotenv').config()
const express = require("express");
const morgan = require('morgan');
const routes = require("./routes");
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3001;

// Define middleware here
app.use(morgan('dev'));

app.use(express.urlencoded({ extended: true }));
app.use(express.json());


// Add routes, both API and view
app.use(routes);
// Serve up static assets (usually on heroku)
app.use(express.static("client/build"));

// Start the API server
app.listen(PORT, function() {
  console.log(`  ==> API Server now listening on PORT ${PORT}!`);
});

Thanks

0 Answers
Related