make a HTTP Request from React-Redux from localhost

我们两清 提交于 2019-12-25 11:58:26

问题


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/fakeemail@gmail.com/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


回答1:


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!



来源:https://stackoverflow.com/questions/46271093/make-a-http-request-from-react-redux-from-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!