![](/img/trans.png)
[英]React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)
[英]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
我正在做電子商務項目。 但是突然在啟動 npm 一段時間后開始反應它給我一個錯誤,比如
Proxy error: Could not proxy request /api/v1/products?keyword=&page=1&price[gte]=0&price[lte]=25000&ratings[gte]=0 from localhost:3000 to http://192.168.0.8:4000.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ETIMEDOUT).
Proxy error: Could not proxy request /Roboto-Regular.ttf from localhost:3000 to http://192.168.0.8:4000.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ETIMEDOUT).
Proxy error: Could not proxy request /api/v1/me from localhost:3000 to http://192.168.0.8:4000.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ETIMEDOUT).
我的package.json的反應
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.61",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"overlay-navbar": "^1.2.3",
"react": "^18.2.0",
"react-alert": "^7.0.3",
"react-alert-template-basic": "^1.0.2",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-icons": "^4.4.0",
"react-js-pagination": "^3.0.3",
"react-material-ui-carousel": "^2.3.11",
"react-rating-stars-component": "^2.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "^4.0.3",
"react-toastify": "^9.0.3",
"redux": "^4.2.0",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.4.1",
"web-vitals": "^2.1.4",
"webfontloader": "^1.6.28"
},
"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"
]
},
"proxy": "http://192.168.0.8:4000"
}
我的后端(服務器)的 package.json
{
"name": "e-com",
"version": "1.0.0",
"description": "",
"main": "backend/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node backend/server.js",
"dev": "nodemon backend/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.0",
"cloudinary": "^1.30.1",
"cookie-parser": "^1.4.6",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-fileupload": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.5.2",
"nodemailer": "^6.7.8",
"nodemon": "^2.0.19",
"validator": "^13.7.0"
}
}
我嘗試了堆棧溢出的幾個答案,例如添加(斜杠)“代理”:“http://192.168.0.8:4000/”,在任務管理器中殺死節點服務器的任務。 再次重新啟動系統。 沒有任何效果,全部更改為 ECONNREFUSED --> ETIMEDOUT 任何幫助,請!
經過無數次的搜索。 我忘記了,我在反應 package.json 中給出的 Ip 地址不是動態地址。 我終於能夠做到了。 我只是將代理更改為“代理”:“http://localhost:4000”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.