Connecting React App to Google Cloud

wwwoworksidehost.com

I can access the database MongoDB database through the Google Cloud connection that I set up. You can try it yourself: workside-software.wl.r.appspot.com/api/project. You can see that this returns the expected data.

Both of my React Native apps can also do full CRUD operations using the exact same interface. I have to conclude that the database and the Google Cloud interface work just fine.

I have deployed a static website on Netlify before (without a backend) and it is working just fine. I can upload the website through Github and the pages work fine. No interface problems There must be some parameters or settings that are required. The database access works with other apps and the web, and the interface has no problems. I have included the api calls for both testing (which works) and production (which does not).

On the backend I do use cors as shown below:

// middleware
app.use(express.json());
app.use(cors({ origin: true, credentials: true }));

app.use((req, res, next) => {
    // console.log(req.path, req.method);
    next();
});

When running the app locally, I have included the following in my package.json:

“proxy”: “https:///workside-software.wl.r.appspot.com”,

and make calls as such:

const fetchString = `/api/user/${userName}?password=${password}`;
const response = await fetch(fetchString).then((r) => {
....
});

This works perfectly.

Prior to deploying to Netlify I make the following change:

const fetchString = `https://workside.appspot.com/api/user/${userName}?password=${password}`;
const response = await fetch(fetchString).then((r) => {
....
});

I have also included in the root directory of my app a netlify.toml file with the following content:

[[redirects]]
  from = "/api/*"
    to = "https://workside.appspot.com/:splat"
  force = true
  status = 200

The result is this from the console:

Failed to load resource: the server responded with a status of 404 () api/firm:1

Failed to load resource: the server responded with a status of 404 ()

workside.appspot.com/api/project/%7D:1

Any suggestions?

@suntan-superman It’s hard to tell from the snippets you’ve provided, but I suspect your code hasn’t been written to work with Serverless Functions and that you’re running into this:
https://answers.netlify.com/t/support-guide-can-i-run-a-web-server-http-listener-and-or-database-at-netlify/3078

Netlify doesn’t provide runtime Node.js based hosting.

I can see you’re trying to use Express though, so you could read: