简体   繁体   English

代理错误:无法将请求 /adduser 从 localhost:3000 代理到 http://127.0.0.1/4000

[英]Proxy error: Could not proxy request /adduser from localhost:3000 to http://127.0.0.1/4000

I am getting an error like "Internal Server Error" don't know where am wrong, please try to solve my query, I you have any query please free feel to ask.我收到类似“内部服务器错误”的错误,不知道哪里错了,请尝试解决我的问题,如果您有任何疑问,请随时提问。

错误页面

package.json package.json

This is my frontend package.json file where i added proxy to communicate with backend.这是我的前端 package.json 文件,我在其中添加了代理以与后端通信。

{
  "name": "todo",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://127.0.0.1/4000/",
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

user.js用户.js

This is the user.js file in their i wrote my logical part这是我写的逻辑部分中的 user.js 文件

const User = require("../model/userdata");

// Get All Users
exports.getAllUser = async (req, res) => {
  User.find().exec((err, users) => {
    if (err || !users) {
      return res.status(400).json({
        err: "No Users Found",
      });
    }
    res.json(users);
  });
};

// Add a single User
exports.addUser = (req, res) => {
  const user = new User(req.body);
  user.save((err, user) => {
    if (err) {
      console.log("ERROR:", err);
      return res.status(400).json({
        err: "not able to connect",
      });
    }
    res.json({
      id: user._id,
      name: user.name,
      email: user.email,
      phone: user.phone,
    });
  });
};

// Get a Single User
exports.getUserById = (req, res) => {
  const id = req.params.id;
  User.findById(id, (err, user) => {
    if (err) {
      return res.status(400).json({
        err: "No User Found",
      });
    }
    res.json(user);
    console.log(user);
  });
};

// Edit User
exports.editUser = (req, res) => {
  const id = req.params.id;
  User.findByIdAndUpdate(
    id,
    {
      $set: req.body,
    },
    (err, user) => {
      if (err) {
        return res.status(400).json({
          err: "User Updation Failed",
        });
      }
      res.json("User Updated Successfully");
    }
  );
};

exports.deleteUser = (req, res) => {
  let id = req.params.id;
  User.findByIdAndRemove(id, (err, user) => {
    if (err) {
      return res.status(400).json({
        err: "Not able to deleted",
      });
    }
    res.json("User Deleted Succefully..");
  });
};

user.js用户.js

This is the route of the user这是用户的路线

const express = require("express");
const {
  getAllUser,
  addUser,
  getUserById,
  deleteUser,
  editUser,
} = require("../controller/user");

const route = express.Router();

route.get("/", getAllUser);
route.post("/adduser", addUser);
route.get("/:id", getUserById);
route.delete("/:id", deleteUser);
route.put("/:id", editUser);

module.exports = route;

Like the error message suggests, 500 Internal Server Error there is something wrong on your server-side.就像错误消息所暗示的那样, 500 Internal Server Error您的服务器端有问题。 You should do the debugging there.你应该在那里进行调试。 This question is not remotely related to React.这个问题与 React 无关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 React 和 Express 的插座 IO。 ReactJS 错误:无法代理请求 /socket.io/?EIO=4… 从 localhost:3000 到 http://127.0.0.1:4000 - Socket IO with React and Express. ReactJS Error: Could not proxy request /socket.io/?EIO=4… from localhost:3000 to http://127.0.0.1:4000 ReactProxy 错误:无法将请求 /api 从 localhost:3000 代理到 http://192.168.0.8:4000。 在几次尝试后被 ECONNREFUSED 之前 --> ETIMEDOUT - ReactProxy error:Could not proxy request /api from localhost:3000 to http://192.168.0.8:4000. Before it was ECONNREFUSED after few tries --> ETIMEDOUT 代理错误:无法代理请求/用户从 localhost:3000 到 http://localhost:5000/ - Proxy error: Could not proxy request /users from localhost:3000 to http://localhost:5000/ 代理错误:无法将请求/用户从localhost:3000代理到http:// localhost:3001 / - Proxy error: Could not proxy request /users from localhost:3000 to http://localhost:3001/ React 代理错误:无法代理请求 /api/ 从 localhost:3000 到 http://localhost:8000 (ECONNREFUSED) - React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED) 出现错误:无法将请求/ api / plaid / accounts从localhost:3000代理到http:// localhost:5000 / - getting error : Could not proxy request /api/plaid/accounts from localhost:3000 to http://localhost:5000/ “React 代理错误:无法将请求 /api/ 从 localhost:3000 代理到 http://localhost:5000 (ECONNREFUSED)”?错误.. 没有在线解决方案 - "React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:5000 (ECONNREFUSED)'? Error.. No solution online 代理错误:无法代理请求 /api/house-listing 从 localhost:3000 到 http://localhost:5000? (ECONNRESET)、MERN - Proxy error: Could not proxy request /api/house-listing from localhost:3000 to http://localhost:5000? (ECONNRESET), MERN Docker 代理错误:无法从 localhost:3000 代理请求 /api/product/B002QYW8LW 到 http://localhost:5000 - Docker proxy error: Could not proxy request /api/product/B002QYW8LW from localhost:3000 to http://localhost:5000 无法将请求 /user/register 从 localhost:3000 代理到 http://localhost:3002/ - Could not proxy request /user/register from localhost:3000 to http://localhost:3002/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM