0

I make a server call using fetch API except one post request all another post/get request hit on the exactly/desire server URL, but the one post requests hit on the localhost server.

service class code and base URL for the post request is the same as others.

service.js:56 POST http://localhost:3000/.... 500 (Internal Server Error)

Code:

function save(workflow) {
    const token = authenticationGenerator.generateAuthenticationToken(localStorage.getItem('username'),
        localStorage.getItem('password'));

    const requestOptions = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        body: JSON.stringify(workflow)
    };
    return fetch('/workflow', requestOptions)
        .then(handleResponse).then(workflowData => {
            return workflowData;
        });
}

... hit on localhost ...

function save(phase) {
    const token = authenticationGenerator.generateAuthenticationToken(localStorage.getItem('username'),
        localStorage.getItem('password'));
    const requestOptions = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        body: JSON.stringify(phase)
    };
    return fetch('/phases', requestOptions)
        .then(handleResponse).then(phaseData => {
            return phaseData;
        });
}

...package.json ...

"scripts": {
    "start": "react-scripts start",
    "build": "webpack --mode production",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
},
"proxy": "http://url../v1",
"eslintConfig": {
    "extends": "react-app"
},

1 Answers1

0

Do you have correct routing for /phases location at the server end?

Iiro Niemi
  • 11
  • 3
  • Those functions have same name and same amount of parameters, are you sure they don't get mixed up in the calling end? I mean, how do you know which one gets called? – Iiro Niemi Nov 08 '19 at 12:09
  • URL endpoint and requestionOption method are different ... baseurl/phase and baseurl/workflow – Shujaat Ali Nov 11 '19 at 04:41