'Post request to the firebase cloud functions gives error 500

I have a POST request to the Cloud Functions on Firebase. When I'm trying to make a request, I get a CORS policy error. Ok, I set mode: 'no-cors' and get Failed to load resource: the server responded with a status of 500 ().

Here is the code

 let myHeaders = new Headers();
 myHeaders.append("Content-Type", "application/json");
 myHeaders.append("Accept", "application/json");

 let raw = JSON.stringify({
    "description": "Test item",
    "email": "[email protected]"
 });

 let requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: raw,
    mode: 'no-cors',
    redirect: 'follow',
 };

 fetch("https://someURl.cloudfunctions.net/someRequest", requestOptions)
 .then(response => response.text())
 .then(result => console.log(result))
 .catch(error => console.log('error', error));

The code is copied from Postman

Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source