ReactJS + Redux:为什么得到 'POST' net::ERR_CONNECTION_REFUSED?

ReactJS + Redux: Why getting 'POST' net::ERR_CONNECTION_REFUSED?

我目前正在关注 https://auth0.com/blog/secure-your-react-and-redux-app-with-jwt-authentication/,我几乎也做了同样的事情,但我仍然收到以下错误:

http://localhost:3001/sessions/create下来了吗?如果不是,错误的原因可能是什么?

提前致谢!

编辑

我也将我的 Express 设置为端口 3000,就像教程中显示的那样并使用了相同的 API url.

问题可能是因为您没有在 API 调用中设置基数 URL。

例如,如果您使用 Auth0 作为服务,则请求中的 API URL 必须如下所示,

axios.post('https://your.auth0.url/sessions/create', data);

(假设您使用的是axios

我假设当前配置如下,

axios.post('/sessions/create', data);

并且它采用相对 URL 并且它将来自服务于基页呈现的应用程序,在您的情况下是 localhost:3001

建议将基础 url (http://auth0.your.url) 保留为环境变量,并且可以在 运行 应用程序时提供。

如果您正在使用 webpack,请查看 Webpack define plugin。