Reactjs redux: Fetch PUT method sending only OPTIONS method, even if status is 200

I am sending the PUT method (see chrome):

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    console.log("status: ", response.statusText);
    return response
  } else {
    var error = new Error(response.statusText)
    error.response = response
    throw error
  }
}

import fetch from 'isomorphic-fetch'
return dispatch => {
        dispatch(requestPosts(data));
        return fetch('/trendings', {
            method: 'PUT',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                Authorization: Config.token
            },
            body: JSON.stringify(data),
        })
        .then(checkStatus)
        .then(reponse => {
            console.log('request succeeded with JSON response', data);
            dispatch(successSent("The output list has been successfully sent!"));
        }).catch(err => {
            console.log('request failed', err);
            dispatch(failSent("Error on sending request: " + err));
        });

and the problem is that it returns the OPTIONS method with only status 200.

The problem is that it must follow using the PUT method. In addition, it should return an error because the API endpoint is not ready yet.

Did I miss something?

+4
source share
1 answer

credentials: 'same-origin' 'Content-Type' : 'application.json' , isomorphic-fetch, , , , isormophic-fetch OPTION ( -):

import fetch from 'isomorphic-fetch'
return dispatch => {
        dispatch(requestPosts(data));
        return fetch('/trendings', {
            method: 'PUT',
            headers: {
                'Accept': 'application/json',
                'Authorization': Config.token
            },
            credentials: 'same-origin', // you need to add this line
            body: JSON.stringify(data),
        })
        .then(checkStatus)
        .then(reponse => {
            console.log('request succeeded with JSON response', data);
            dispatch(successSent("The output list has been successfully sent!"));
        }).catch(err => {
            console.log('request failed', err);
            dispatch(failSent("Error on sending request: " + err));
        });
+2

All Articles