简体   繁体   English

我的应用程序将 localhost:3000 作为服务器。 但我有 localhost:4000 作为服务器

[英]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.

相关问题 无法打开我的开发服务器(localhost:3000) - Cannot open my development server (localhost:3000) 当我想将 localhost:4000 重定向到 localhost:3000 时出现错误 CORS - Error CORS when i want redirecting localhost:4000 to localhost:3000 如何让我的 React 应用程序在 localhost:3000 中编译 - How can I get my react app to compile in localhost:3000 GET http://localhost:3000/:/localhost:4000 404(未找到) - GET http://localhost:3000/:/localhost:4000 404 (Not Found) React js 没有在 localhost:3000 上运行我的应用程序 - React js isn't running my app on localhost:3000 我的 React 应用程序在 localhost:3000 上显示空白屏幕,没有任何错误 - My React App shows a blank white screen on localhost:3000 with no errors 我的 React 应用程序在 LocalHost 上运行非常缓慢,但在 Live Server 中运行良好。 UI 渲染很慢。 可能的原因是什么? - My React App is working very slow on LocalHost but it is working fine in Live Server. UI Rendering is very slow. What could be the possible cause? 为什么我不断收到 500(内部服务器错误)GET http://localhost:3000/favicon.ico 500(内部服务器错误)? - Why do I keep getting a 500(Internal Server Error) GET http://localhost:3000/favicon.ico 500 (Internal Server Error)? localhost:3000 和 Internet 上的生产服务器 (localhost:5000) 上的代码相同但行为不同 - Same code but different behavior on localhost:3000 and on production server on the Internet (localhost:5000) 试图使axios反应从localhost:8080到Rails服务器localhost:3000的请求 - Trying to make axios react request from localhost:8080 to a rails server localhost:3000
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM