From fcb818fd2fa24f7be9e3ddcef451ef21e9a35f1d Mon Sep 17 00:00:00 2001 From: Italo A Date: Wed, 8 Nov 2023 23:31:48 +0000 Subject: [PATCH 01/14] feat: add pino logger and update prisma to fix bug --- backend/package-lock.json | 409 +++++++++++++++++++++++++++++++++++--- backend/package.json | 9 +- 2 files changed, 392 insertions(+), 26 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 04da5fd9..2d9a90aa 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -20,16 +20,19 @@ "@nestjs/platform-socket.io": "^9.0.0", "@nestjs/serve-static": "^4.0.0", "@nestjs/websockets": "^9.0.0", - "@prisma/client": "^4.12.0", - "argon2": "^0.31.1", + "@prisma/client": "^4.16.2", + "argon2": "^0.30.3", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "cookie-parser": "^1.4.6", "ms": "^2.1.3", + "nestjs-pino": "^3.5.0", "otplib": "^12.0.1", "passport": "^0.6.0", "passport-jwt": "^4.0.1", "passport-oauth2": "^1.7.0", + "pino-http": "^8.5.1", + "pino-pretty": "^10.2.3", "qrcode": "^1.5.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.2.0" @@ -56,7 +59,7 @@ "eslint-plugin-prettier": "^4.0.0", "jest": "29.5.0", "prettier": "^2.3.2", - "prisma": "^4.12.0", + "prisma": "^4.16.2", "source-map-support": "^0.5.20", "supertest": "^6.1.3", "ts-jest": "29.0.5", @@ -1973,12 +1976,12 @@ } }, "node_modules/@prisma/client": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.12.0.tgz", - "integrity": "sha512-j9/ighfWwux97J2dS15nqhl60tYoH8V0IuSsgZDb6bCFcQD3fXbXmxjYC8GHhIgOk3lB7Pq+8CwElz2MiDpsSg==", + "version": "4.16.2", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.16.2.tgz", + "integrity": "sha512-qCoEyxv1ZrQ4bKy39GnylE8Zq31IRmm8bNhNbZx7bF2cU5aiCCnSa93J2imF88MBjn7J9eUQneNxUQVJdl/rPQ==", "hasInstallScript": true, "dependencies": { - "@prisma/engines-version": "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7" + "@prisma/engines-version": "4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81" }, "engines": { "node": ">=14.17" @@ -1993,16 +1996,16 @@ } }, "node_modules/@prisma/engines": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.12.0.tgz", - "integrity": "sha512-0alKtnxhNB5hYU+ymESBlGI4b9XrGGSdv7Ud+8TE/fBNOEhIud0XQsAR+TrvUZgS4na5czubiMsODw0TUrgkIA==", + "version": "4.16.2", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.16.2.tgz", + "integrity": "sha512-vx1nxVvN4QeT/cepQce68deh/Turxy5Mr+4L4zClFuK1GlxN3+ivxfuv+ej/gvidWn1cE1uAhW7ALLNlYbRUAw==", "devOptional": true, "hasInstallScript": true }, "node_modules/@prisma/engines-version": { - "version": "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7.tgz", - "integrity": "sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA==" + "version": "4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81.tgz", + "integrity": "sha512-q617EUWfRIDTriWADZ4YiWRZXCa/WuhNgLTVd+HqWLffjMSPzyM5uOWoauX91wvQClSKZU4pzI4JJLQ9Kl62Qg==" }, "node_modules/@sinclair/typebox": { "version": "0.25.24", @@ -2772,6 +2775,17 @@ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -3024,6 +3038,14 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/axios": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", @@ -3135,7 +3157,6 @@ "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "dev": true, "funding": [ { "type": "github", @@ -3630,6 +3651,11 @@ "color-support": "bin.js" } }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -3802,6 +3828,14 @@ "node": ">= 8" } }, + "node_modules/dateformat": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", + "engines": { + "node": "*" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -4037,7 +4071,6 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, "dependencies": { "once": "^1.4.0" } @@ -4401,11 +4434,18 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "dev": true, "engines": { "node": ">=0.8.x" } @@ -4568,6 +4608,11 @@ "node": ">=4" } }, + "node_modules/fast-copy": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-3.0.1.tgz", + "integrity": "sha512-Knr7NOtK3HWRYGtHoJrjkaWepqT8thIVGAwt0p0aUs1zqkAzXZV4vo9fFNwyb5fcqK1GKYFYxldQdIDVKhUAfA==" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -4608,6 +4653,14 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "node_modules/fast-redact": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.3.0.tgz", + "integrity": "sha512-6T5V1QK1u4oF+ATxs1lWUmlEk6P2T9HqJG3e2DnHOdVgZy2rFJBoEnrIedcTXlkAHU/zKC+7KETJ+KGGKwxgMQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/fast-safe-stringify": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", @@ -5097,6 +5150,65 @@ "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" }, + "node_modules/help-me": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-4.2.0.tgz", + "integrity": "sha512-TAOnTB8Tz5Dw8penUuzHVrKNKlCIbwwbHnXraNJxPwf8LRtE2HlM84RYuezMFcwOJmoYOCWVDyJ8TQGxn9PgxA==", + "dependencies": { + "glob": "^8.0.0", + "readable-stream": "^3.6.0" + } + }, + "node_modules/help-me/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/help-me/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/help-me/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/help-me/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -5163,7 +5275,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, "funding": [ { "type": "github", @@ -6088,6 +6199,14 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/joycon": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", + "integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==", + "engines": { + "node": ">=10" + } + }, "node_modules/js-sdsl": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz", @@ -6600,6 +6719,19 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/nestjs-pino": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/nestjs-pino/-/nestjs-pino-3.5.0.tgz", + "integrity": "sha512-IWJ3dzLVjg5istcd3Cz3rVO+gmvabfVAT1YmQgzL1HnC2hkc0H6qA6k6SZ7OIwQfewuRejYfPu3TlkxwRrqxHQ==", + "hasInstallScript": true, + "engines": { + "node": ">= 14" + }, + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "pino-http": "^6.4.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/node-abort-controller": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz", @@ -6726,6 +6858,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -7066,6 +7206,168 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pino": { + "version": "8.16.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.16.1.tgz", + "integrity": "sha512-3bKsVhBmgPjGV9pyn4fO/8RtoVDR8ssW1ev819FsRXlRNgW8gR/9Kx+gCK4UPWd4JjrRDLWpzd/pb1AyWm3MGA==", + "dependencies": { + "atomic-sleep": "^1.0.0", + "fast-redact": "^3.1.1", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "v1.1.0", + "pino-std-serializers": "^6.0.0", + "process-warning": "^2.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^3.7.0", + "thread-stream": "^2.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.1.0.tgz", + "integrity": "sha512-lsleG3/2a/JIWUtf9Q5gUNErBqwIu1tUKTT3dUzaf5DySw9ra1wcqKjJjLX1VTY64Wk1eEOYsVGSaGfCK85ekA==", + "dependencies": { + "readable-stream": "^4.0.0", + "split2": "^4.0.0" + } + }, + "node_modules/pino-abstract-transport/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/pino-abstract-transport/node_modules/readable-stream": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", + "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/pino-abstract-transport/node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/pino-http": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/pino-http/-/pino-http-8.5.1.tgz", + "integrity": "sha512-T/3d9YHKBYpv/QHjNy73P5BNYYkRrC2/D6CxKMecG4fKFLN+B2iC6LsKYzGRTRV+Ld3fjxFC1ca4TUGbPdzk+Q==", + "dependencies": { + "get-caller-file": "^2.0.5", + "pino": "^8.0.0", + "pino-std-serializers": "^6.0.0", + "process-warning": "^2.0.0" + } + }, + "node_modules/pino-pretty": { + "version": "10.2.3", + "resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-10.2.3.tgz", + "integrity": "sha512-4jfIUc8TC1GPUfDyMSlW1STeORqkoxec71yhxIpLDQapUu8WOuoz2TTCoidrIssyz78LZC69whBMPIKCMbi3cw==", + "dependencies": { + "colorette": "^2.0.7", + "dateformat": "^4.6.3", + "fast-copy": "^3.0.0", + "fast-safe-stringify": "^2.1.1", + "help-me": "^4.0.1", + "joycon": "^3.1.1", + "minimist": "^1.2.6", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^1.0.0", + "pump": "^3.0.0", + "readable-stream": "^4.0.0", + "secure-json-parse": "^2.4.0", + "sonic-boom": "^3.0.0", + "strip-json-comments": "^3.1.1" + }, + "bin": { + "pino-pretty": "bin.js" + } + }, + "node_modules/pino-pretty/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/pino-pretty/node_modules/readable-stream": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", + "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/pino-pretty/node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/pino-std-serializers": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", + "integrity": "sha512-cHjPPsE+vhj/tnhCy/wiMh3M3z3h/j15zHQX+S9GkTBgqJuTuJzYJ4gUyACLhDaJ7kk9ba9iRDmbH2tJU03OiA==" + }, "node_modules/pirates": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", @@ -7219,13 +7521,13 @@ } }, "node_modules/prisma": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.12.0.tgz", - "integrity": "sha512-xqVper4mbwl32BWzLpdznHAYvYDWQQWK2tBfXjdUD397XaveRyAP7SkBZ6kFlIg8kKayF4hvuaVtYwXd9BodAg==", + "version": "4.16.2", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.16.2.tgz", + "integrity": "sha512-SYCsBvDf0/7XSJyf2cHTLjLeTLVXYfqp7pG5eEVafFLeT0u/hLFz/9W196nDRGUOo1JfPatAEb+uEnTQImQC1g==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines": "4.12.0" + "@prisma/engines": "4.16.2" }, "bin": { "prisma": "build/index.js", @@ -7235,11 +7537,24 @@ "node": ">=14.17" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, + "node_modules/process-warning": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-2.3.0.tgz", + "integrity": "sha512-N6mp1+2jpQr3oCFMz6SeHRGbv6Slb20bRhj4v3xR99HqNToAcOe1MFOp4tytyzOfJn+QtN8Rf7U/h2KAn4kC6g==" + }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -7275,7 +7590,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -7466,6 +7780,11 @@ } ] }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==" + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -7534,6 +7853,14 @@ "node": ">=8.10.0" } }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "engines": { + "node": ">= 12.13.0" + } + }, "node_modules/rechoir": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", @@ -7771,6 +8098,14 @@ } ] }, + "node_modules/safe-stable-stringify": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", + "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "engines": { + "node": ">=10" + } + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -7825,6 +8160,11 @@ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, + "node_modules/secure-json-parse": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", + "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==" + }, "node_modules/semver": { "version": "7.3.8", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", @@ -8031,6 +8371,14 @@ "node": ">=10.0.0" } }, + "node_modules/sonic-boom": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.7.0.tgz", + "integrity": "sha512-IudtNvSqA/ObjN97tfgNmOKyDOs4dNcg4cUUsHDebqsgb8wGBBwb31LIgShNO8fye0dFI52X1+tFoKKI6Rq1Gg==", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, "node_modules/source-map": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", @@ -8059,6 +8407,14 @@ "node": ">=0.10.0" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -8174,7 +8530,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, "engines": { "node": ">=8" }, @@ -8424,6 +8779,14 @@ "node": ">=0.2.6" } }, + "node_modules/thread-stream": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-2.4.1.tgz", + "integrity": "sha512-d/Ex2iWd1whipbT681JmTINKw0ZwOUBZm7+Gjs64DHuX34mmw8vJL2bFAaNacaW72zYiTJxSHi5abUuOi5nsfg==", + "dependencies": { + "real-require": "^0.2.0" + } + }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/backend/package.json b/backend/package.json index c012f6c6..c952b4ad 100644 --- a/backend/package.json +++ b/backend/package.json @@ -35,16 +35,19 @@ "@nestjs/platform-socket.io": "^9.0.0", "@nestjs/serve-static": "^4.0.0", "@nestjs/websockets": "^9.0.0", - "@prisma/client": "^4.12.0", - "argon2": "^0.31.1", + "@prisma/client": "^4.16.2", + "argon2": "^0.30.3", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "cookie-parser": "^1.4.6", "ms": "^2.1.3", + "nestjs-pino": "^3.5.0", "otplib": "^12.0.1", "passport": "^0.6.0", "passport-jwt": "^4.0.1", "passport-oauth2": "^1.7.0", + "pino-http": "^8.5.1", + "pino-pretty": "^10.2.3", "qrcode": "^1.5.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.2.0" @@ -71,7 +74,7 @@ "eslint-plugin-prettier": "^4.0.0", "jest": "29.5.0", "prettier": "^2.3.2", - "prisma": "^4.12.0", + "prisma": "^4.16.2", "source-map-support": "^0.5.20", "supertest": "^6.1.3", "ts-jest": "29.0.5", From 07c6b02f102a2dd01bdb471050ebc163a2540d35 Mon Sep 17 00:00:00 2001 From: Italo A Date: Wed, 8 Nov 2023 23:31:57 +0000 Subject: [PATCH 02/14] feat: add global logger --- backend/src/app.module.ts | 11 +++++++++++ backend/src/main.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 2b875426..ce7d0927 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -12,9 +12,20 @@ import { AvatarUploadModule } from './avatar-upload/avatar-upload.module'; import { MatchHistoryModule } from './match-history/match-history.module'; import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; +import { LoggerModule } from 'nestjs-pino'; @Module({ imports: [ + LoggerModule.forRoot({ + pinoHttp: { + transport: { + target: 'pino-pretty', + options: { + singleLine: true, + }, + }, + }, + }), ConfigModule.forRoot({ isGlobal: true, }), diff --git a/backend/src/main.ts b/backend/src/main.ts index ddeccd86..65a93c65 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -2,9 +2,11 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import cookieParser from 'cookie-parser'; import { ValidationPipe } from '@nestjs/common'; +import { Logger } from 'nestjs-pino'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { bufferLogs: true }); + app.useLogger(app.get(Logger)); // Set up cookie parser app.use(cookieParser()); From e32f0bca3a0a9f2fd0b829242c5d1c41f2a7cbc5 Mon Sep 17 00:00:00 2001 From: "Italo A." Date: Wed, 8 Nov 2023 23:37:30 +0000 Subject: [PATCH 03/14] feat: instantiate logger into chat --- backend/src/chat/chat.gateway.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/chat/chat.gateway.ts b/backend/src/chat/chat.gateway.ts index 5df61398..bf212973 100644 --- a/backend/src/chat/chat.gateway.ts +++ b/backend/src/chat/chat.gateway.ts @@ -11,7 +11,7 @@ import { } from '@nestjs/websockets'; import { Server, Socket } from 'socket.io'; import { ChatService } from './chat.service'; -import { ParseIntPipe } from '@nestjs/common'; +import { Logger, ParseIntPipe } from '@nestjs/common'; import { ChatDto, ChatMessageDto, @@ -38,6 +38,7 @@ export class ChatGateway private usersService: UsersService, ) {} private connectedUsers: ConnectedUsers = {}; + private readonly logger = new Logger(ChatGateway.name); @WebSocketServer() server: Server; @@ -563,6 +564,7 @@ export class ChatGateway next(); }) .catch((err) => { + this.logger.error(err); return next(new Error(err)); }); }); @@ -577,6 +579,7 @@ export class ChatGateway }); return this.usersService.findOne(payload.sub); } catch { + this.logger.error('Token invalid or expired'); throw new WsException('Token invalid or expired'); } } From c4adcb80262612de6ef7747e3478746fdbcc2a1a Mon Sep 17 00:00:00 2001 From: Italo A Date: Thu, 9 Nov 2023 23:39:44 -0300 Subject: [PATCH 04/14] refactor: remove dev container --- .devcontainer/Dockerfile | 15 ---------- .devcontainer/devcontainer.json | 29 -------------------- .devcontainer/docker-compose.yml | 44 ------------------------------ .devcontainer/postCreateCommand.sh | 16 ----------- 4 files changed, 104 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/devcontainer.json delete mode 100644 .devcontainer/docker-compose.yml delete mode 100755 .devcontainer/postCreateCommand.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index faf316ac..00000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM mcr.microsoft.com/devcontainers/javascript-node:20 - -RUN apt-get update \ - && apt install -y \ - # Utilities - bash-completion \ - # Docker requirements - apt-transport-https ca-certificates gnupg2 lsb-release \ - # Install docker gpg key - && curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - 2>/dev/null \ - # Add docker to apt sources - && echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list \ - && apt-get update \ - # Install Docker - && apt-get install -y docker-ce-cli docker-compose-plugin diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 853faf62..00000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "42 Transcendence", - "dockerComposeFile": ["docker-compose.yml"], - "service": "transcendence", - "workspaceFolder": "/workspaces/transcendence", - "postCreateCommand": "./.devcontainer/postCreateCommand.sh", - // Features to add to the dev container. More info: https://containers.dev/features. - "features": {}, - "customizations": { - "vscode": { - "extensions": [ - "naumovs.color-highlight", - "ms-azuretools.vscode-docker", - "EditorConfig.EditorConfig", - "dbaeumer.vscode-eslint", - "GitHub.copilot", - "eamodio.gitlens", - "esbenp.prettier-vscode", - "Prisma.prisma", - "Prisma.prisma-insider", - "bradlc.vscode-tailwindcss" - ] - } - }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // This can be used to network with other containers or with the host. - "forwardPorts": [3000, 5432, 8080, 8000] -} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index e1ec4ac9..00000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,44 +0,0 @@ - -services: - transcendence: - container_name: transcendence_devcontainer - build: - context: . - dockerfile: Dockerfile - working_dir: /workspaces/transcendence - entrypoint: /bin/sh -c 'tail --follow /dev/null' - volumes: - # Map host folder to workspace - - ..:/workspaces/transcendence - # Allow docker socket to use docker CLI inside devcontainer - - /var/run/docker.sock:/var/run/docker.sock - networks: - - backend - - postgres: - container_name: transcendence_dev_postgres - image: postgres:latest - restart: unless-stopped - ports: - - "5432:5432" - networks: - - backend - environment: - POSTGRES_DB: "postgres" - POSTGRES_USER: "user" - POSTGRES_PASSWORD: "password" - - dbadmin: - container_name: transcendence_dev_adminer - image: adminer - restart: unless-stopped - ports: - - "8080:8080" - networks: - - backend - depends_on: - - postgres - -networks: - backend: - driver: bridge diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh deleted file mode 100755 index 7f0c8ebd..00000000 --- a/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Install dependencies -cd backend/ && npm ci - -# Install NestJS CLI -npm install -g @nestjs/cli - -# Generate Prisma Client -npm run prisma:generate - -# Generate Prisma Migrations -npx prisma db push --force-reset && npx prisma db seed - -# Docker daemon setup -sudo chown node:node /var/run/docker.sock From a42893cfd224a53b57d77cf932160bde91627efc Mon Sep 17 00:00:00 2001 From: Italo A Date: Thu, 9 Nov 2023 23:39:59 -0300 Subject: [PATCH 05/14] feat: move post create command --- backend/scripts/postCreateCommand.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 backend/scripts/postCreateCommand.sh diff --git a/backend/scripts/postCreateCommand.sh b/backend/scripts/postCreateCommand.sh new file mode 100755 index 00000000..ea14247b --- /dev/null +++ b/backend/scripts/postCreateCommand.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Install dependencies +cd backend/ && npm i + +# Install NestJS CLI +npm install -g @nestjs/cli + +# Generate Prisma Client +npx prisma generate + +# Generate Prisma Migrations +npx prisma db push --force-reset && npx prisma db seed From a5f71d012b6aaadb46a74befc9b5e1550c082c15 Mon Sep 17 00:00:00 2001 From: Italo A Date: Thu, 9 Nov 2023 23:40:37 -0300 Subject: [PATCH 06/14] refactor: simplify docker files --- backend/Dockerfile | 25 +++++------------ frontend/Dockerfile | 66 +++++---------------------------------------- 2 files changed, 13 insertions(+), 78 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 0a55f982..aa74c48f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,24 +1,13 @@ -################### -# BUILD FOR LOCAL DEVELOPMENT -################### +FROM node:18 -# Base image -FROM node:18 AS development +WORKDIR /usr/src/app/server -# Set working directory -WORKDIR /usr/src/app +COPY . . -# Copy package.json and package-lock.json -COPY --chown=node:node package*.json ./ +RUN npm install +RUN npm run build -# Install dependencies -RUN npm ci -RUN npm install -g @nestjs/cli +EXPOSE 3000 -# Copy source code -COPY --chown=node:node . . +CMD [ "npm", "run", "start" ] -# Generate Prisma database client code -RUN npm run prisma:generate - -ENTRYPOINT [ "npm", "run", "start:dev" ] diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 35e553c9..9b4d55de 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,67 +1,13 @@ -FROM node:18-alpine AS base +FROM node:18 -FROM node:18-alpine AS development +WORKDIR /usr/src/app/client -WORKDIR /app - -COPY package.json package-lock.json* ./ - -RUN npm ci - -COPY . . - -CMD ["npm", "run", "dev"] - - -# Install dependencies only when needed -FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat -WORKDIR /app - -# Install dependencies based on the preferred package manager -COPY package.json package-lock.json* ./ -RUN npm ci - - -# Rebuild the source code only when needed -FROM base AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules COPY . . -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry during the build. -# ENV NEXT_TELEMETRY_DISABLED 1 - -RUN yarn build - -# If using npm comment out above and use below instead -# RUN npm run build - -# Production image, copy all the files and run next -FROM base AS runner -WORKDIR /app - -ENV NODE_ENV production -# Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED 1 - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs - -COPY --from=builder /app/public ./public - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - -USER nextjs +RUN npm install +RUN npm build -EXPOSE 3000 +EXPOSE 9090 -ENV PORT 3000 +CMD [ "npm", "run", "start", "--port", "9090" ] -CMD ["node", "server.js"] \ No newline at end of file From ce5fc50b29862a2d3c9410283a1b08ffd186b87a Mon Sep 17 00:00:00 2001 From: Italo A Date: Thu, 9 Nov 2023 23:42:51 -0300 Subject: [PATCH 07/14] feat: create a temporary db for dev --- .gitignore | 1 + docker-compose-db.yml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 docker-compose-db.yml diff --git a/.gitignore b/.gitignore index e417b397..234c8186 100644 --- a/.gitignore +++ b/.gitignore @@ -113,3 +113,4 @@ postgres/ # Local Uploads /backend/uploads/* +data diff --git a/docker-compose-db.yml b/docker-compose-db.yml new file mode 100644 index 00000000..18db3834 --- /dev/null +++ b/docker-compose-db.yml @@ -0,0 +1,18 @@ +version: "3.8" + +# create a postgres service +services: + postgres: + container_name: nestjs-postgres + image: postgres + restart: always + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_HOST: ${POSTGRES_HOST} + PGDATA: /data/postgres + ports: + - 5432:5432 + volumes: + - ./data/pg:/data/postgres From e7c6e3bbecfe54f0631515a758c00aedaaae6bcf Mon Sep 17 00:00:00 2001 From: Italo A Date: Tue, 14 Nov 2023 22:30:18 -0300 Subject: [PATCH 08/14] feat: add ngrok configs --- backend/Dockerfile | 5 +++- backend/scripts/postCreateCommand.sh | 6 ---- docker-compose-db.yml | 18 ------------ docker-compose-dev.yml | 44 ++++++++++++++++++++++++++++ frontend/Dockerfile | 11 ++++--- 5 files changed, 53 insertions(+), 31 deletions(-) delete mode 100644 docker-compose-db.yml create mode 100644 docker-compose-dev.yml diff --git a/backend/Dockerfile b/backend/Dockerfile index aa74c48f..ad43f964 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,9 +4,12 @@ WORKDIR /usr/src/app/server COPY . . -RUN npm install +RUN npm i RUN npm run build +# Run postCreate script +RUN chmod a+x ./scripts/postCreateCommand.sh + EXPOSE 3000 CMD [ "npm", "run", "start" ] diff --git a/backend/scripts/postCreateCommand.sh b/backend/scripts/postCreateCommand.sh index ea14247b..6541f43c 100755 --- a/backend/scripts/postCreateCommand.sh +++ b/backend/scripts/postCreateCommand.sh @@ -1,11 +1,5 @@ #!/bin/bash -# Install dependencies -cd backend/ && npm i - -# Install NestJS CLI -npm install -g @nestjs/cli - # Generate Prisma Client npx prisma generate diff --git a/docker-compose-db.yml b/docker-compose-db.yml deleted file mode 100644 index 18db3834..00000000 --- a/docker-compose-db.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.8" - -# create a postgres service -services: - postgres: - container_name: nestjs-postgres - image: postgres - restart: always - environment: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_HOST: ${POSTGRES_HOST} - PGDATA: /data/postgres - ports: - - 5432:5432 - volumes: - - ./data/pg:/data/postgres diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 00000000..eb5ef2e2 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,44 @@ +version: "3.8" + +# create a postgres service +services: + postgres: + container_name: nestjs-postgres + image: postgres + restart: always + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_HOST: ${POSTGRES_HOST} + PGDATA: /data/postgres + ports: + - 5432:5432 + volumes: + - ./data/pg:/data/postgres + backend: + container_name: nestjs-backend + build: + context: ./backend + dockerfile: Dockerfile + restart: always + ports: + - 3000:3000 + depends_on: + - postgres + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_HOST=${POSTGRES_HOST} + ngrok: + image: wernight/ngrok + restart: always + depends_on: + - backend + environment: + - NGROK_PORT=backend:3000 + - NGROK_AUTH=${NGROK_AUTH} + - NGROK_HOSTNAME=${NGROK_HOSTNAME} + ports: + - 4040:4040 diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 9b4d55de..73daa461 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,13 +1,12 @@ -FROM node:18 +FROM node:20 WORKDIR /usr/src/app/client COPY . . -RUN npm install -RUN npm build +RUN yarn install +RUN yarn build -EXPOSE 9090 - -CMD [ "npm", "run", "start", "--port", "9090" ] +EXPOSE 3000 +CMD [ "yarn", "start" ] From fb98424adda4c6b0e63c62330eb0992560f99244 Mon Sep 17 00:00:00 2001 From: Italo A Date: Tue, 14 Nov 2023 22:43:04 -0300 Subject: [PATCH 09/14] feat: update example --- .env.example | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..98dc06a6 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +POSTGRES_DB="db" +POSTGRES_USER="user" +POSTGRES_PASSWORD="pass" +POSTGRES_HOST="host" +NGROK_AUTH="authngrok" +NGROK_HOSTNAME="hostname" \ No newline at end of file From 88b22be57db001c29d7bc78cbe6f6b62f457a095 Mon Sep 17 00:00:00 2001 From: Italo A Date: Wed, 15 Nov 2023 19:58:02 -0300 Subject: [PATCH 10/14] fix: hardcoded domain --- frontend/src/contexts/GameContext.tsx | 2 +- frontend/src/services/chatClient.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/contexts/GameContext.tsx b/frontend/src/contexts/GameContext.tsx index 16ca53af..0f888cfa 100644 --- a/frontend/src/contexts/GameContext.tsx +++ b/frontend/src/contexts/GameContext.tsx @@ -88,7 +88,7 @@ export const GameProvider = ({ children }: GameProviderProps) => { // Listen for the 'connect' event const { accessToken } = nookies.get(null, "accesssToken"); - socket.current = io("http://localhost:3000/game", { + socket.current = io(`${process.env.NEXT_PUBLIC_API_URL}/game`, { auth: { token: accessToken, }, diff --git a/frontend/src/services/chatClient.ts b/frontend/src/services/chatClient.ts index 8d7cf66b..6328be8a 100644 --- a/frontend/src/services/chatClient.ts +++ b/frontend/src/services/chatClient.ts @@ -12,7 +12,7 @@ class ChatService { if (!this.socket) { const { accessToken } = nookies.get(null, "accesssToken"); - this.socket = io("http://localhost:3000/chat", { + this.socket = io(`${process.env.NEXT_PUBLIC_API_URL}/chat`, { auth: { token: accessToken, }, From 15fde68aadf8be6229a9fea0a83fafa3038b8f8d Mon Sep 17 00:00:00 2001 From: Italo A Date: Wed, 15 Nov 2023 20:07:30 -0300 Subject: [PATCH 11/14] fix: update package.lock --- backend/package-lock.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 2d9a90aa..267c491d 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -2994,14 +2994,14 @@ "dev": true }, "node_modules/argon2": { - "version": "0.31.1", - "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.31.1.tgz", - "integrity": "sha512-ik2xnJrLXazya7m4Nz1XfBSRjXj8Koq8qF9PsQC8059p20ifWc9zx/hgU3ItZh/3TnwXkv0RbhvjodPkmFf0bg==", + "version": "0.30.3", + "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.30.3.tgz", + "integrity": "sha512-DoH/kv8c9127ueJSBxAVJXinW9+EuPA3EMUxoV2sAY1qDE5H9BjTyVF/aD2XyHqbqUWabgBkIfcP3ZZuGhbJdg==", "hasInstallScript": true, "dependencies": { - "@mapbox/node-pre-gyp": "^1.0.11", + "@mapbox/node-pre-gyp": "^1.0.10", "@phc/format": "^1.0.0", - "node-addon-api": "^7.0.0" + "node-addon-api": "^5.0.0" }, "engines": { "node": ">=14.0.0" @@ -6739,9 +6739,9 @@ "dev": true }, "node_modules/node-addon-api": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.0.0.tgz", - "integrity": "sha512-vgbBJTS4m5/KkE16t5Ly0WW9hz46swAstv0hYYwMtbG7AznRhNyfLRe8HZAiWIpcHzoO7HxhLuBQj9rJ/Ho0ZA==" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" }, "node_modules/node-emoji": { "version": "1.11.0", From 2a9306100bd99bdcf945f1743f0f342f48f38726 Mon Sep 17 00:00:00 2001 From: Italo A Date: Thu, 16 Nov 2023 20:08:55 -0300 Subject: [PATCH 12/14] feat: add handle connection prisma --- backend/src/prisma/prisma.service.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/src/prisma/prisma.service.ts b/backend/src/prisma/prisma.service.ts index 60a30ba2..c23e236c 100644 --- a/backend/src/prisma/prisma.service.ts +++ b/backend/src/prisma/prisma.service.ts @@ -1,9 +1,22 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; import { PrismaClient } from '@prisma/client'; @Injectable() -export class PrismaService extends PrismaClient { +export class PrismaService + extends PrismaClient + implements OnModuleInit, OnModuleDestroy +{ constructor() { - super(); + super({ + log: ['warn', 'error'], + }); + } + + onModuleInit() { + return this.$connect(); + } + + onModuleDestroy() { + return this.$disconnect(); } } From 911afed2d1349f8706236dacd365f4aae3b8283e Mon Sep 17 00:00:00 2001 From: Italo A Date: Fri, 17 Nov 2023 21:36:17 -0300 Subject: [PATCH 13/14] feat: working ngrok --- backend/.env.example | 27 ++++++++++----------------- backend/Dockerfile | 5 +---- backend/package.json | 6 ++++-- backend/scripts/postCreateCommand.sh | 7 ------- docker-compose-db.yml | 16 ++++++++++++++++ docker-compose-dev.yml | 18 +++++++++--------- frontend/.env.example | 2 +- 7 files changed, 41 insertions(+), 40 deletions(-) delete mode 100755 backend/scripts/postCreateCommand.sh create mode 100644 docker-compose-db.yml diff --git a/backend/.env.example b/backend/.env.example index defa9404..2e049d05 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,23 +1,16 @@ -DOMAIN="" # domain to use for cookies (default: localhost) -APP_NAME="Confia Driven Development" -FRONTEND_URL="http://localhost:9000" -############################### Prisma Setup ################################ -POSTGRES_USER="user" -POSTGRES_PASSWORD="password" -POSTGRES_DB="postgres" -POSTGRES_HOST="postgres" - -DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?schema=public" +DOMAIN="example.vercel.app" # domain to use for cookies (default: localhost) +APP_NAME="Example app name" +FRONTEND_URL="https://example.vercel.app" ############################### Intra Auth Setup ############################### -INTRA_CLIENT_ID="" -INTRA_CLIENT_SECRET="" -INTRA_CALLBACK_URL="http://localhost:3000/auth/intra/callback" +INTRA_CLIENT_ID="u-s4t2ud-example" +INTRA_CLIENT_SECRET="s-s4t2ud-example" +INTRA_CALLBACK_URL="http://example.ngrok-free.app/auth/intra/callback" ################################## JWT Secret ################################## -JWT_SECRET="" -ACCESS_TOKEN_EXPIRATION="" # 15m # Increase to stay logged in for longer without refreshing -REFRESH_TOKEN_EXPIRATION="" # 7d # after this time, the user will have to log in again +JWT_SECRET="the-example-secret" +ACCESS_TOKEN_EXPIRATION="60m" # 15m # Increase to stay logged in for longer without refreshing +REFRESH_TOKEN_EXPIRATION="7d" # 7d # after this time, the user will have to log in again ################################## HASH Secret ################################## -HASH_PEPPER="" # At least 16 bytes long for security (128 bits) (32 bytes recommended) +HASH_PEPPER="the-example-hash" # At least 16 bytes long for security (128 bits) (32 bytes recommended) diff --git a/backend/Dockerfile b/backend/Dockerfile index ad43f964..99dfc840 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -7,10 +7,7 @@ COPY . . RUN npm i RUN npm run build -# Run postCreate script -RUN chmod a+x ./scripts/postCreateCommand.sh - EXPOSE 3000 -CMD [ "npm", "run", "start" ] +CMD [ "npm", "run", "start:docker" ] diff --git a/backend/package.json b/backend/package.json index c952b4ad..f99734e0 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,9 +19,11 @@ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", "prisma:generate": "npx prisma generate", - "prisma:migrate": "npx prisma migrate dev --name init", + "prisma:migrate": "npx prisma migrate deploy", "prisma:reset": "npx prisma db push --force-reset", - "prisma:studio": "npx prisma studio" + "prisma:studio": "npx prisma studio", + "prestart:docker": "npm run prisma:generate && npm run prisma:migrate", + "start:docker": "nest start" }, "dependencies": { "@nestjs/axios": "^2.0.0", diff --git a/backend/scripts/postCreateCommand.sh b/backend/scripts/postCreateCommand.sh deleted file mode 100755 index 6541f43c..00000000 --- a/backend/scripts/postCreateCommand.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Generate Prisma Client -npx prisma generate - -# Generate Prisma Migrations -npx prisma db push --force-reset && npx prisma db seed diff --git a/docker-compose-db.yml b/docker-compose-db.yml new file mode 100644 index 00000000..fd3bea7c --- /dev/null +++ b/docker-compose-db.yml @@ -0,0 +1,16 @@ +services: + postgres: + container_name: nestjs-postgres + image: postgres + restart: always + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_HOST: ${POSTGRES_HOST} + DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB} + PGDATA: /data/postgres + ports: + - 5432:5432 + volumes: + - ./data/pg:/data/postgres diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index eb5ef2e2..a1872b2b 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -3,7 +3,7 @@ version: "3.8" # create a postgres service services: postgres: - container_name: nestjs-postgres + container_name: database image: postgres restart: always environment: @@ -17,7 +17,7 @@ services: volumes: - ./data/pg:/data/postgres backend: - container_name: nestjs-backend + container_name: backend build: context: ./backend dockerfile: Dockerfile @@ -27,18 +27,18 @@ services: depends_on: - postgres environment: - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_HOST=${POSTGRES_HOST} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB} ngrok: image: wernight/ngrok restart: always depends_on: - backend environment: - - NGROK_PORT=backend:3000 - - NGROK_AUTH=${NGROK_AUTH} - - NGROK_HOSTNAME=${NGROK_HOSTNAME} + NGROK_PORT: backend:3000 + NGROK_AUTH: ${NGROK_AUTH} + NGROK_HOSTNAME: ${NGROK_HOSTNAME} ports: - 4040:4040 diff --git a/frontend/.env.example b/frontend/.env.example index c22987f7..662f900f 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,2 +1,2 @@ ############################### React Setup ################################ -NEXT_PUBLIC_API_URL="localhost:3000" \ No newline at end of file +NEXT_PUBLIC_API_URL="localhost:6000" \ No newline at end of file From f67e1a3430e91035baca874a6e896f0bbd2e6a65 Mon Sep 17 00:00:00 2001 From: Italo A Date: Fri, 17 Nov 2023 21:37:04 -0300 Subject: [PATCH 14/14] feat: add skip ngrok page --- frontend/src/services/api.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index debe5c81..81dae4aa 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -16,6 +16,10 @@ export function setupAPIClient(ctx: Context = undefined) { config.headers["Authorization"] = `Bearer ${accessToken}`; } + // add ngrok-skip-browser-warning + // https://ngrok.com/docs#global-configuration + config.headers["ngrok-skip-browser-warning"] = "true"; + return config; },