0

I am new to React Redux, and All I already did:

1) activate my backend server (localhost:5000)

2) activate my front-end server using npm start (localhost:8080)

3) I tried to dispatch action by using

this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile});

4) Using atlas-saga, and call my service function associated with the dispatch :

let result = yield call(Atlas.uploadFile, action.email, action.file);

5) define the function as :

export const uploadFile = (email, file) => { return fetch(`${BASE_URL}/v1/files/${email}/policies`, { method: 'POST', headers:{} , body: {'file': file} }) .then(response => response.json()) }

After I try to run a function at my react( a function that calls the dispatch), it gives me errors that they cannot found the route. This is the error message from the console.

Fetch API cannot load https://api-staging.autoarmour.co/v1/files/[email protected]/policies. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 500. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Yes, I did not create any reducer, just pure function that will upload a file. Thank you

3
  • 1
    i think problem is the server api-staging.autoarmour.co not accept a request from 'localhost:8080'. Commented Sep 18, 2017 at 3:26
  • Thanks bro, I will wait for other solutions Commented Sep 18, 2017 at 3:32
  • check this link stackoverflow.com/questions/20035101/… for more details about this issue Commented Sep 18, 2017 at 3:43

1 Answer 1

0

I SOLVE IT, WOHOO!!! The error message means that its not connected at the backend side at all. You need to make sure that it is connected. I solve it by connecting my redux to my react component. Thanks guys

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.