【发布时间】:2016-10-01 13:08:13
【问题描述】:
我有一个使用 webpack 捆绑的 web 应用程序,我将整个 react/redux 应用程序放在由 nodejs(express-generator) 提供的公共文件中。当我在 localhost/local 环境中运行时,我的应用程序可以工作。但是,当我部署到 heroku 时。我不能打电话。
以下是错误信息:
bundle.js:19 GET https://glacial-cove-64389.herokuapp.com/users/ 401 (Unauthorized)
Object {err: Error: Request failed with status code 401 at e.exports (https://glacial-cove-64389.herokuapp.co…}
err
:
Error: Request failed with status code 401 at e.exports (https://glacial-cove-64389.herokuapp.com/bundle.js:19:10382) at e.exports (https://glacial-cove-64389.herokuapp.com/bundle.js:26:6821) at XMLHttpRequest._.(anonymous function) (https://glacial-cove-64389.herokuapp.com/bundle.js:19:9464)
__proto__
:
Object
最初我认为它可能是我的 ROOT_URL,所以我更改了它,下面是我的操作文件的示例。
const ROOT_URL = "//glacial-cove-64389.herokuapp.com"
const axiosOption = {headers: { authorization : localStorage.getItem('token')}}
/*Sign in user*/
export function signinUser({ email, password }){
return function(dispatch){
axios.post(`${ROOT_URL}/users/signin`, { email, password })
.then(function(res){
dispatch({ type: AUTH_USER })
localStorage.setItem('token', res.data.token);
browserHistory.push('/users');
})
.catch(function(err){
dispatch(authError('Invalid email or password'))
console.log({err});
})
}
}
所以发生的情况是反应识别登录并将用户推送到正确的路线。但是一旦它到达主页,它就会返回上述错误消息状态码 401。
我遇到的主要问题是当我尝试执行不起作用的 CRUD 时
【问题讨论】:
标签: ajax node.js reactjs heroku redux