Browse Source

chore: Added backend debug .env option and added .vscode

Co-authored-by: Kristian Vos <k.vos@kvos.dev>
Owen Diffey 2 years ago
parent
commit
36d36d9705

+ 2 - 0
.env.example

@@ -6,6 +6,8 @@ DOCKER_COMMAND=docker
 BACKEND_HOST=127.0.0.1
 BACKEND_PORT=8080
 BACKEND_MODE=prod
+BACKEND_DEBUG=false
+BACKEND_DEBUG_PORT=9229
 
 FRONTEND_HOST=127.0.0.1
 FRONTEND_PORT=80

+ 0 - 1
.gitignore

@@ -2,7 +2,6 @@ Thumbs.db
 .DS_Store
 *.swp
 .idea/
-.vscode/
 .vagrant/
 
 .env

+ 10 - 0
.vscode/extensions.json

@@ -0,0 +1,10 @@
+{
+    "recommendations": [
+        "ms-azuretools.vscode-docker",
+        "dbaeumer.vscode-eslint",
+        "eamodio.gitlens",
+        "rvest.vs-code-prettier-eslint",
+        "Vue.vscode-typescript-vue-plugin",
+        "Vue.volar"
+    ]
+}

+ 21 - 0
.vscode/launch.json

@@ -0,0 +1,21 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Docker: Attach to Node",
+            "type": "node",
+            "request": "attach",
+            "port": 9229,
+            "address": "localhost",
+            "localRoot": "${workspaceFolder}/backend",
+            "remoteRoot": "/opt/app/",
+            "autoAttachChildProcesses": true,
+            "restart": true,
+            "continueOnAttach": true,
+            "smartStep": true
+        }
+    ]
+}

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
+}

+ 2 - 0
.wiki/Configuration.md

@@ -120,6 +120,8 @@ application within the container is listening on `21017`.
 | `BACKEND_HOST` | Backend container host. |
 | `BACKEND_PORT` | Backend container port. |
 | `BACKEND_MODE` | Should be either `prod` or `dev`. |
+| `BACKEND_DEBUG` | Should be either `true` or `false`. If enabled backend will await debugger connection and trigger to start. |
+| `BACKEND_DEBUG_PORT` | Backend container debug port, if enabled. |
 | `FRONTEND_HOST` | Frontend container host. |
 | `FRONTEND_PORT` | Frontend container port. |
 | `FRONTEND_MODE` | Should be either `prod` or `dev`. |

+ 6 - 0
backend/entrypoint.sh

@@ -7,4 +7,10 @@ if [[ "${CONTAINER_MODE}" == "dev" ]]; then
     fi
 fi
 
+if [[ "${BACKEND_DEBUG}" == "true" ]]; then
+    export INSPECT_BRK="--inspect-brk=0.0.0.0"
+else
+    export INSPECT_BRK=""
+fi
+
 npm run "${BACKEND_MODE}"

+ 8 - 5
backend/nodemon.json

@@ -1,6 +1,9 @@
 {
-  "watch": ["src", "config"],
-  "ext": "ts,json",
-  "ignore": ["src/**/*.spec.ts", "node_modules"],
-  "exec": "ts-node ./src/main.ts"
-}
+	"watch": ["src", "config"],
+	"ext": "ts,json",
+	"ignore": ["src/**/*.spec.ts", "node_modules"],
+	"stdin": true,
+	"stdout": true,
+	"signal": "SIGUSR2",
+	"exec": "NODE_OPTIONS=${INSPECT_BRK} ts-node -i ./src/main.ts"
+}

+ 3 - 0
docker-compose.dev.yml

@@ -2,8 +2,11 @@ services:
   backend:
     ports:
       - "${BACKEND_HOST:-0.0.0.0}:${BACKEND_PORT:-8080}:8080"
+      - "${BACKEND_HOST:-0.0.0.0}:${BACKEND_DEBUG_PORT:-9229}:9229"
     volumes:
       - ./backend:/opt/app
+    environment:
+      - BACKEND_DEBUG=${BACKEND_DEBUG:-false}
 
   frontend:
     volumes: