Request from ::1: POST /.netlify/functions Response with status 404

66 views Asked by At

so I am new to netlify. I keep getting a 404 error every time I make a request. This is react, and for the JS code:

await fetch('./.netlify/functions/create-payment-intent.js', {
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ message: "test"}),
                }).then((res) => {
                    return res.json();
                });

Terminal:

Request from ::1: POST /.netlify/functions/create-payment-intent.js
Response with status 404 in 3 ms

In the debugger:

POST http://localhost:8888/.netlify/functions/example.js 404 (Not Found)

Please how do I fix this? Thanks.

1

There are 1 answers

0
Asma On

What I know about fetch function is that it takes 'URL' as an parameter not a file, your fetch code be like

fetch('https://some-api-call') basically Fetch's basic function is to work with API. For the details you may check out this link : https://www.javascripttutorial.net/javascript-fetch-api/