From 01327a9a17d9966853066feac8e1fe4a5f806122 Mon Sep 17 00:00:00 2001 From: Ninja GPT Date: Mon, 4 Mar 2024 17:57:07 -0600 Subject: [PATCH] adds debugger --- .devcontainer/devcontainer.json | 2 +- .vscode/launch.json | 13 ++++++ Dockerfile | 5 +-- docker-compose.yml | 6 +-- package.json | 2 + src/index.ts | 7 ++-- yarn.lock | 72 +++++++++++++-------------------- 7 files changed, 50 insertions(+), 57 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5198158..05a3f94 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,7 +12,7 @@ "extensions": [ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode" - ], + ] } }, diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..82dd2ca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch via NPM", + "type": "node", + "request": "launch", + "cwd": "${workspaceFolder}", + "runtimeExecutable": "yarn", + "runtimeArgs": ["debug"] + } + ] + } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5ccce59..feac56e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,4 @@ RUN yarn # Copy compiled JavaScript from the builder stage COPY --from=builder /app/dist ./dist -EXPOSE 3330 - -# Command to run the application -CMD ["yarn", "dev"] \ No newline at end of file +EXPOSE 3330 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 97a72f3..42a4ef4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,16 +8,16 @@ services: volumes: - .:/app - /app/node_modules - command: ["yarn", "dev"] ports: - - '3330:3330' + - "9229:9229" # Debugger port + - '3330:3330' # Dev port environment: - MONGO_URI=mongodb://mongodb:27017/node-auth depends_on: - mongodb networks: - myapp-network - + command: ["tail", "-f", "/dev/null"] mongodb: image: mongo:latest diff --git a/package.json b/package.json index 54d666b..90fa821 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "build": "rimraf ./dist && tsc", "dev": "nodemon", + "debug": "NODE_ENV=debug nodemon --inspect=0.0.0.0:9229 src/index.ts", "start": "node dist/index.js", "lint": "eslint 'src/**/*.{js,ts}' --fix", "format": "prettier --write 'src/**/*.{js,ts,json,css,md}'", @@ -34,6 +35,7 @@ "typescript": "*" }, "dependencies": { + "dotenv": "^16.4.5", "mongodb": "^6.3.0", "mongoose": "^8.0.3" } diff --git a/src/index.ts b/src/index.ts index 0b95148..6a7a308 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,12 +3,11 @@ import { connectDB } from './data/database'; import { router } from './routers/userRouter'; // Use a function to safely parse environment variables -function getPort(defaultPort: number): number { - const port = process.env.PORT; - return port !== undefined ? parseInt(port, 10) : defaultPort; +function getPort(): number { + return process.env.NODE_ENV === 'debug' ? 9229 : 3330; } -const PORT: number = getPort(3330); +const PORT: number = getPort(); // Define types for Request and Response to improve readability and type safety type HttpRequest = http.IncomingMessage; diff --git a/yarn.lock b/yarn.lock index 5b51b5d..1700217 100644 --- a/yarn.lock +++ b/yarn.lock @@ -110,7 +110,7 @@ "@nodelib/fs.stat" "2.0.5" run-parallel "^1.1.9" -"@nodelib/fs.stat@^2.0.2", "@nodelib/fs.stat@2.0.5": +"@nodelib/fs.stat@2.0.5", "@nodelib/fs.stat@^2.0.2": version "2.0.5" resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz" integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A== @@ -615,6 +615,13 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2: shebang-command "^2.0.0" which "^2.0.1" +debug@4.x, debug@^4, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4: + version "4.3.4" + resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + debug@^3.2.7: version "3.2.7" resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz" @@ -622,13 +629,6 @@ debug@^3.2.7: dependencies: ms "^2.1.1" -debug@^4, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@4.x: - version "4.3.4" - resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" - integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== - dependencies: - ms "2.1.2" - deep-is@^0.1.3: version "0.1.4" resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz" @@ -678,6 +678,11 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dotenv@^16.4.5: + version "16.4.5" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" + integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== + dynamic-dedupe@^0.3.0: version "0.3.0" resolved "https://registry.npmjs.org/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz" @@ -1555,26 +1560,19 @@ micromatch@^4.0.4: braces "^3.0.2" picomatch "^2.3.1" -minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: - version "3.1.2" - resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz" - integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== - dependencies: - brace-expansion "^1.1.7" - -minimatch@^9.0.1: +minimatch@9.0.3, minimatch@^9.0.1: version "9.0.3" resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz" integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg== dependencies: brace-expansion "^2.0.1" -minimatch@9.0.3: - version "9.0.3" - resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz" - integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg== +minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: + version "3.1.2" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== dependencies: - brace-expansion "^2.0.1" + brace-expansion "^1.1.7" minimist@^1.2.0, minimist@^1.2.6: version "1.2.8" @@ -1599,7 +1597,7 @@ mongodb-connection-string-url@^3.0.0: "@types/whatwg-url" "^11.0.2" whatwg-url "^13.0.0" -mongodb@^6.3.0, mongodb@6.3.0: +mongodb@6.3.0, mongodb@^6.3.0: version "6.3.0" resolved "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz" integrity sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA== @@ -1633,16 +1631,16 @@ mquery@5.0.0: dependencies: debug "4.x" -ms@^2.1.1, ms@2.1.3: - version "2.1.3" - resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" - integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== - ms@2.1.2: version "2.1.2" resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +ms@2.1.3, ms@^2.1.1: + version "2.1.3" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz" @@ -2031,16 +2029,7 @@ sparse-bitfield@^3.0.3: dependencies: memory-pager "^1.0.2" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -2085,14 +2074,7 @@ string.prototype.trimstart@^1.0.7: define-properties "^1.2.0" es-abstract "^1.22.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==