从localhost从React-Redux发出HTTP请求

时间:2017-09-18 03:13:41

标签: httprequest react-redux redux-saga web-development-server

我是React Redux的新手,而且我已经做过了所有人:

1)激活我的后端服务器(localhost:5000)

2)使用npm start(localhost:8080)激活我的前端服务器

3)我尝试使用

发送动作

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

4)使用atlas-saga,并调用与发送相关联的服务功能:

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

5)将函数定义为:

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

在我尝试在我的反应中运行一个函数(一个调用调度的函数)之后,它给了我错误,他们找不到路由。这是来自控制台的错误消息。

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.

是的,我没有创建任何reducer,只是用于上传文件的纯函数。谢谢

1 个答案:

答案 0 :(得分:0)

我解决了它,WOHOO !!! 错误消息表示它根本没有连接在后端。您需要确保它已连接。我通过将我的redux连接到我的react组件来解决它。谢谢你们

干杯!