[英]How To Attach Visual Studio Code Debugger to Node.JS Application running on docker machine behind nginx proxy
我正在嘗試將調試器附加到node.js應用程序。 到目前為止,我沒有運氣,它始終在此錯誤消息中結束:
以下是我設置系統的方法:
我有三個容器在不同的網絡上運行:
我有一個前端容器,帶有客戶端javascript和html代碼,在nginx服務器上運行。 nginx還將服務器作為API的代理。
API位於快遞容器中。 它是在端口3000上運行的node.js應用程序。
然后我有一個用於持久性的mongo容器。
Docker-為科技創作。 細節:
version: '3.0' # specify docker-compose version
# Define the services/ containers to be run
services:
frontend:
container_name: frontend
build: frontend
ports:
- '80:80'
- '443:443'
networks:
- front
express: # name of the second service
container_name: express
build: express-server # specify the directory of the Dockerfile
ports:
- '9229:9229'
networks:
- front
- backbone
mongo: # name of the third service
container_name: mongo
image: mongo # specify image to build container from
volumes:
- "db:/data/db"
networks:
- backbone
networks:
front:
driver: bridge
backbone:
driver: bridge
volumes:
db:
如前所述,前端容器將“/ api”子域的調用路由到相應的快遞容器。 因此api不能通過它的端口訪問,而是通過路由(因此它只能在https中工作)。
還有一個重定向從80 - > 443,因為https和chromes關於http和https網站的新政策。
server {
listen 80;
server_name _;
return 301 https://$host$request_uri;
}
server {
ssl on;
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
listen *:443 ssl;
server_name _;
root /var/www;
index index.html;
location /api/ {
rewrite ^/api/?(.*) /$1 break;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://express:3000;
}
}
該應用程序是一個簡單的REST-API,幾乎開箱即用(感謝表達:))。
然而,一個調用遇到異常,我想正確調試它,所以我嘗試了不同的方法來附加調試器。
我在Visual Studio代碼中配置了我的調試器,如下所示:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "<docker-machine-ip>",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/express-server\\app.js"
}
]
}
打開直接訪問api並通過nginx刪除路由,然后打開快速容器上的調試端口並嘗試調試:得到超時並且錯誤:連接ECONNREFUSED
使用socat容器嘗試了本指南: https ://codefresh.io/docker-tutorial/debug_node_in_docker/ - 沒有成功
在調試模式下啟動應用程序,連接到容器並通過cli進行調試 - 無法從Web客戶端訪問API
Canlde輕量級調試,當你必須在每個console.log()之后重建時執行起來很糟糕
如果您需要更多信息評論,我真的很感激提示或者教程。
也許我錯過了什么
沒關系我解決了這個問題。
我不得不改變我啟動應用程序的方式(通過節點檢查而不是npm start)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.