[英]my app is taking localhost:3000 as the server. but i have localhost:4000 as the server
My problem is that iam using axios to communicate with backend.axios had done perfect job till now.我的问题是我使用 axios 与后端进行通信。axios 到目前为止已经完成了完美的工作。 but when i wrote a code for register, my console says that POST http://localhost:3000/api/v1/register 500 (Internal Server Error)
但是当我编写注册代码时,我的控制台说 POST http://localhost:3000/api/v1/register 500(内部服务器错误)
so till now it responded very good.but now it thrwing an error like this.所以到目前为止它的反应非常好。但现在它抛出了这样的错误。
userAction.js:用户操作.js:
export const register = (userData) => async (dispatch) => {
try {
dispatch({ type: REGISTER_USER_REQUEST });
const config = { headers: { "Content-Type": "multipart/form-data" } };
const { data } = await axios.post("/api/v1/register", userData, config);
dispatch({ type: REGISTER_USER_SUCCESS, payload: data.user });
} catch (error) {
dispatch({
type: REGISTER_USER_FAIL,
payload: error.response.data.message,
});
}
};
iam using localhost:4000 as server.我使用 localhost:4000 作为服务器。 but it showing me localhost:3000 which means my app url
但它向我显示 localhost:3000 这意味着我的应用程序 url
Because you did not specify the host in your post url.Then it may be work.因为您没有在帖子 url 中指定主机。那么它可能会起作用。
/api/v1/register => http://localhost/api/v1/register
The if you have cors issue add this to the nodejs backend app.js file (as you using nodejs):如果您有 cors 问题,请将其添加到 nodejs 后端 app.js 文件(当您使用 nodejs 时):
const cors = require('cors');
app.use(cors())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.