Issue sending POST request to Express site

I’m attempting to send a POST request to a Netlify website through a React Native app. The details of the request aren’t important, as it simply sends an email with the provided data.

The issue is that this works flawlessly on localhost. I have my site running on a development server locally, and the POST request goes through with ease. However, when I push the same code to Netlify, I get no response from the POST request. This is difficult to debug, as there are no error messages I can turn to.

For reference, my website code is taken from this Netlify Express Repo: https://github.com/neverendingqs/netlify-express with only a few modified lines.

The code for sending the POST request in my app is as follows:

 fetch('https://livesantaclaus.com/api/email', {
     method: "POST",
     headers: {
         'Accept': 'application/json, text/plain, */*',
         'Content-Type': 'application/json'
     },
     body: JSON.stringify(body)
 })
 .catch(err => { })

Thank you so much for any help you can provide.

Netlify Site Name: https://livesantaclaus.netlify.app
Site name: https://www.livesantaclaus.com

Is this a netlify function? There seems to be no endpoint at https://livesantaclaus.com/api/email?

I believe so, yes. When Netlify is building it, it builds everything in the “express” folder to Netlify functions.

That repo I linked to should help to clarify.

Ok, so, the only function that would get created is /functions/server.js and that would end up at the endpoint https://www.livesantaclaus.com/.netlify/functions/server.

Unless you plan to proxy rewrite the function to /api/email, that endpoint does not exist.

I see. So can I use that URL for the request, or how would that work?

In server.js, I have an app.post(’/api/email’)… function that accepts a post request. Would I append “api/email” to the URL you provided or do I simply send the request to that URL?

Alternatively, is using Netlify functions slightly redundant in this instance? Is there an easier way to setup API endpoints on Netlify?

Thanks so much for your time!

I haven’t reviewed your code, but you can use this for reference:

1 Like