我有 2 個容器:
- nginx(服務于 React 應用程式)
- 節點
兩者都在同一個 docker-compose 檔案中。
當我在本地運行它時('npm start' 用于 React 和 node index.js 用于后端)它們作業正常(后端接收請求) - 但是當它們都在容器中時,出現問題..
** 當我執行 nginx 容器時 - 它確實識別 http://server:5000/ 端點(使用 curl)
docker-compose.yaml
version: "3.8"
services:
server:
build:
context: ./server
ports:
- "5000:5000"
networks:
- frontend
nginx:
build:
context: ./app
restart: always
ports:
- "80:80"
networks:
- frontend
networks:
frontend:
在前端請求部分
async function sendMsg(...order){
await axios.put('http://server:5000/msg', order)
}
在后端接收部分
app.put('/msg', (req, res) => {
console.log(req.body)
}
uj5u.com熱心網友回復:
問題是您的反應應用程式由您的容器提供服務,但在您的瀏覽器中執行。
您的瀏覽器不知道“服務器”指的是什么。
嘗試將 http://server:5000/msg 更改為 http://localhost:5000/msg
還要確保您的節點服務器正在運行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415689.html
標籤:
上一篇:選擇值更改時組件道具不更改
下一篇:誰來設計和實作FRONTEND(nginx&react)和BACKEND(laravel&mongo)的容器化架構
