From 9149bba8688582cc48d6f2a504809bfb33b20c43 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Thu, 1 May 2025 16:07:55 -0700 Subject: [PATCH 1/5] added password hashing --- assignment-db-service/.env.development | 14 ++ assignment-db-service/{dev.env => .env.test} | 2 + assignment-db-service/app.js | 54 ++++---- assignment-db-service/package-lock.json | 123 ++++++++++++++++++ assignment-db-service/package.json | 5 +- assignment-service/.env.development | 6 + assignment-service/.env.test | 6 + assignment-service/package-lock.json | 110 ++++++++++++++++ assignment-service/package.json | 6 +- assignment-service/routes/InstructorRouter.js | 105 +++++++++------ auth-service/{dev.env => .env.development} | 0 compose.yaml | 8 +- user-db-service/{dev.env => .env.development} | 0 13 files changed, 364 insertions(+), 75 deletions(-) create mode 100644 assignment-db-service/.env.development rename assignment-db-service/{dev.env => .env.test} (97%) create mode 100644 assignment-service/.env.development create mode 100644 assignment-service/.env.test rename auth-service/{dev.env => .env.development} (100%) rename user-db-service/{dev.env => .env.development} (100%) diff --git a/assignment-db-service/.env.development b/assignment-db-service/.env.development new file mode 100644 index 0000000..d370b34 --- /dev/null +++ b/assignment-db-service/.env.development @@ -0,0 +1,14 @@ +NODE_ENV=development + +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +#use this when testing local, remmber to run the proxy command +DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" + +# DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" +# DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable +NODE_PORT=3200 diff --git a/assignment-db-service/dev.env b/assignment-db-service/.env.test similarity index 97% rename from assignment-db-service/dev.env rename to assignment-db-service/.env.test index 1e00c54..b464239 100644 --- a/assignment-db-service/dev.env +++ b/assignment-db-service/.env.test @@ -1,3 +1,5 @@ +NODE_ENV=development + # Environment variables declared in this file are automatically made available to Prisma. # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 115c256..09f0055 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -10,8 +10,24 @@ const port = process.env.NODE_PORT || 3000; app.use(express.json()); app.use(express.urlencoded({ extended: true })); +async function encryptPassword(password) { + if (!password) { + return null; + } + + return new Promise((resolve, reject) => { + bcrypt.hash(password, 10, (err, hash) => { + if (err) { + reject(err); + } else { + resolve(hash); + } + }); + }); +} + //function to conver req.body to assignment -function convertToAssignment(req) { +async function convertToAssignment(req) { const { campid, programid, @@ -24,7 +40,8 @@ function convertToAssignment(req) { instructorid } = req.body; - // const hashedPassword = await bcrypt.hash(Password, 10); + const hashPassword = await encryptPassword(req.body.password); + return { campid: campid, programid: programid, @@ -33,8 +50,7 @@ function convertToAssignment(req) { originalfile: originalfile, editablefile: editablefile, assignmenturl: assignmenturl, - // passwordhash: hashedpassword, - passwordhash: password, + passwordhash: hashPassword, instructorid: instructorid, }; } @@ -44,25 +60,11 @@ app.post("/assignments", async (req, res) => { try { console.log("Request body:", req.body); - // const { - // campid, - // programid, - // studentname, - // snakegameid, - // originalfile, - // editablefile, - // assignmenturl, - // password, - // instructorid - // } = req.body; - - // const hashedPassword = await bcrypt.hash(Password, 10); + const assignment = await convertToAssignment(req); const newAssignment = await prisma.assignments.create({ - data: { - ...convertToAssignment(req) - }, + data: assignment, }); - + console.log("Assignment created successfully:", newAssignment); res.json({ @@ -119,17 +121,11 @@ app.get("/assignments/:id", async (req, res) => { app.put("/assignments/:id", async (req, res) => { try { const { id } = req.params; - const data = req.body; - - if (data.password) { - // data.passwordhash = await bcrypt.hash(data.Password, 10); - data.passwordhash = data.password; - delete data.password; - } + const assignment = await convertToAssignment(req); const updatedAssignment = await prisma.assignments.update({ where: { assignmentid: parseInt(id) }, - data, + data: assignment, }); res.json({ diff --git a/assignment-db-service/package-lock.json b/assignment-db-service/package-lock.json index 1f1e538..d88c403 100644 --- a/assignment-db-service/package-lock.json +++ b/assignment-db-service/package-lock.json @@ -10,6 +10,9 @@ "express": "^5.1.0", "nodemon": "^3.1.9", "prisma": "^6.1.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -377,6 +380,21 @@ "node": ">=6.6.0" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", @@ -418,6 +436,45 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -912,6 +969,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -999,6 +1063,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1211,6 +1285,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1454,6 +1538,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -1713,6 +1820,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-db-service/package.json b/assignment-db-service/package.json index ca9db41..6724b9c 100644 --- a/assignment-db-service/package.json +++ b/assignment-db-service/package.json @@ -8,6 +8,9 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "nodemon app.js" + "dev": "dotenv -e .env.development nodemon app.js" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/.env.development b/assignment-service/.env.development new file mode 100644 index 0000000..1bc73e5 --- /dev/null +++ b/assignment-service/.env.development @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test new file mode 100644 index 0000000..d39a82f --- /dev/null +++ b/assignment-service/.env.test @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index 3dff094..683f7be 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -17,6 +17,9 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -393,6 +396,21 @@ "node": ">= 0.10" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -453,6 +471,32 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -1109,6 +1153,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -1196,6 +1247,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1460,6 +1521,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1738,6 +1809,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -2018,6 +2112,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-service/package.json b/assignment-service/package.json index b0a2b99..365e94e 100644 --- a/assignment-service/package.json +++ b/assignment-service/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "dev": "nodemon server.js" + "dev": "dotenv -e .env.development nodemon server.js" }, "keywords": [], "author": "", @@ -11,11 +11,15 @@ "description": "", "dependencies": { "axios": "^1.8.4", + "bcrypt": "^5.1.1", "cors": "^2.8.5", "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index c3a6d01..ffee372 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -2,30 +2,40 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); -const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; +const DB_ASSIGNMENT_SERVICE_URL = + process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); // This endpoint is for instructors to create a new assignment -intructorRouter.post("/create", - // passport.authenticate("jwt", { session: false }), +intructorRouter.post( + "/create", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - console.log("Creating a new assignment with data:", req.body); - const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); - console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); - res.status(response.status).json(response.data); - } catch (error) { - console.error("Error creating assignment:", error.message); - res.status(error.response?.status || 500).json({ error: error.message }); + try { + + console.log("Creating a new assignment with data:", req.body); + const response = await axios.post( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, + req.body + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + res.status(response.status).json(response.data); + } catch (error) { + console.error("Error creating assignment:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to get details of a specific assignment intructorRouter.get("/details/:id", async (req, res) => { try { const assignmentId = req.params.id; console.log("Fetching details for assignmentId:", assignmentId); - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { @@ -35,48 +45,63 @@ intructorRouter.get("/details/:id", async (req, res) => { }); // This endpoint is for instructors to get a list of assignments they have created -intructorRouter.get("/list/:id", async (req, res) => { - // if (req.isAuthenticated()) { +intructorRouter.get( + "/list/:id", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + // if (req.isAuthenticated()) { try { const instructorId = req.params.id; console.log("Fetching assignments for instructorId:", instructorId); // const instructorId = req.user.userid; // Assuming req.user contains the authenticated user - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}` + ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { res.status(error.response?.status || 500).json({ error: error.message }); } - // } else { - // return res.status(401).json({ error: "Not authenticated" }); - // } - -}); + // } else { + // return res.status(401).json({ error: "Not authenticated" }); + // } + } +); // This endpoint is for instructors to update an assignment -intructorRouter.put("/update/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.put( + "/update/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.put(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + + const response = await axios.put( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, + req.body + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to delete an assignment -intructorRouter.delete("/delete/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.delete( + "/delete/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.delete(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + const response = await axios.delete( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); -module.exports = intructorRouter; \ No newline at end of file +module.exports = intructorRouter; diff --git a/auth-service/dev.env b/auth-service/.env.development similarity index 100% rename from auth-service/dev.env rename to auth-service/.env.development diff --git a/compose.yaml b/compose.yaml index 99c6a2d..41c59e6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,7 +11,7 @@ services: ports: - "3200:3200" # Expose port to the same host env_file: - - ./assignment-db-service/dev.env + - ./assignment-db-service/.env.development networks: - backend @@ -25,7 +25,7 @@ services: ports: - "8082:8082" # Expose port to the same host env_file: - - ./assignment-service/dev.env + - ./assignment-service/.env.development depends_on: - js-assignment-db-service networks: @@ -41,7 +41,7 @@ services: ports: - "8080:8080" # Expose port to the same host env_file: - - ./auth-service/dev.env + - ./auth-service/.env.development networks: - backend @@ -55,7 +55,7 @@ services: ports: - "3100:3100" # Expose port to the same host env_file: - - ./user-db-service/dev.env + - ./user-db-service/.env.development networks: - backend diff --git a/user-db-service/dev.env b/user-db-service/.env.development similarity index 100% rename from user-db-service/dev.env rename to user-db-service/.env.development From 9b7e8ab276a983b38226639f3ed220112d1f817c Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 12:41:41 -0700 Subject: [PATCH 2/5] merge with main --- assignment-service/package-lock.json | 198 ++++++++++++++++-- assignment-service/package.json | 1 + assignment-service/routes/InstructorRouter.js | 35 +++- assignment-service/routes/StudentRouter.js | 50 ++++- auth-service/.env.development | 2 + auth-service/package-lock.json | 123 +++++++++++ auth-service/package.json | 6 +- auth-service/passport.js | 61 ++++-- auth-service/routes/auth.js | 10 + uploader-service/app.js | 2 +- 10 files changed, 434 insertions(+), 54 deletions(-) diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index 683f7be..099ea78 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -15,6 +15,7 @@ "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", + "multer": "^1.4.5-lts.2", "nodemon": "^3.1.9", "passport": "^0.7.0" }, @@ -112,6 +113,12 @@ "node": ">= 8" } }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, "node_modules/aproba": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", @@ -240,6 +247,23 @@ "node": ">=8" } }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -338,6 +362,51 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "license": "MIT" }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "engines": [ + "node >= 0.8" + ], + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, + "node_modules/concat-stream/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/concat-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/concat-stream/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -383,6 +452,12 @@ "node": ">=6.6.0" } }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT" + }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -826,20 +901,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "license": "ISC" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -1153,6 +1214,12 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT" + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1251,7 +1318,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1309,6 +1375,79 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/multer": { + "version": "1.4.5-lts.2", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz", + "integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/multer/node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/multer/node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/negotiator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", @@ -1557,6 +1696,12 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "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==", + "license": "MIT" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1931,6 +2076,14 @@ "node": ">= 0.8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -2045,6 +2198,12 @@ "node": ">= 0.6" } }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", + "license": "MIT" + }, "node_modules/uid-safe": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", @@ -2143,6 +2302,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "license": "ISC" }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/assignment-service/package.json b/assignment-service/package.json index 365e94e..7e1714a 100644 --- a/assignment-service/package.json +++ b/assignment-service/package.json @@ -16,6 +16,7 @@ "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", + "multer": "^1.4.5-lts.2", "nodemon": "^3.1.9", "passport": "^0.7.0" }, diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index ffee372..8fa3cff 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -1,23 +1,44 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); +const multer = require('multer'); +const FormData = require('form-data'); + const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); +// Use memory storage to keep file in RAM +const upload = multer({ storage: multer.memoryStorage() }); + + // This endpoint is for instructors to create a new assignment -intructorRouter.post( - "/create", - // passport.authenticate("jwt", { session: false }), +intructorRouter.post("/create", + upload.single('file'), + // passport.authenticate("jwt", { session: false }), async (req, res) => { try { + + const file = req.file; + const assignmentData = req.body; + + if (!file) { + return res.status(400).send('No file uploaded.'); + } + + await axios.post('https://target-api.com/endpoint', { + filename: file.originalname, + mimetype: file.mimetype, + content: file.buffer.toString('base64') + }, { + headers: { + 'Content-Type': 'application/json' + } + }); console.log("Creating a new assignment with data:", req.body); - const response = await axios.post( - `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, - req.body - ); + const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 63f07a2..a84b271 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -1,13 +1,49 @@ const studentRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); +const bcrypt = require("bcrypt"); +require("dotenv").config(); +const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL; -studentRouter.post("/save", (req, res) => { - + +studentRouter.post("/save", (req, res) => {}); + +studentRouter.post("/deploy", (req, res) => {}); + +studentRouter.post("/verify/", async (req, res) => { + try { + const assignmentId = req.body.id; + const password = req.body.password; + console.log( + "Accessing assignment with ID:", + assignmentId, + "and password:", + password + ); + + console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + console.log("Password provided:", password); + console.log("Password hash from database:", response.data.passwordhash); + + const isPasswordValid = await bcrypt.compare( + password, + response.data.passwordhash + ); + + if (!isPasswordValid || !response.data) { + return res.status(401).json({ error: "Invalid id and password" }); + } + + res.status(response.status).json(response.data); + } catch (error) { + console.error("Error fetching assignment details:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } }); -studentRouter.post("/deploy", (req, res) => { - -}); - -module.exports = studentRouter; \ No newline at end of file +module.exports = studentRouter; diff --git a/auth-service/.env.development b/auth-service/.env.development index 794749f..74b17a1 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -1,3 +1,5 @@ +NODE_ENV=development + GOOGLE_CLIENT_ID="485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com" GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" diff --git a/auth-service/package-lock.json b/auth-service/package-lock.json index 495b39d..26d2726 100644 --- a/auth-service/package-lock.json +++ b/auth-service/package-lock.json @@ -16,7 +16,11 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0", + "passport-custom": "^1.1.1", "passport-google-oauth20": "^2.0.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/accepts": { @@ -280,6 +284,21 @@ "node": ">= 0.10" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -325,6 +344,32 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -847,6 +892,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -910,6 +962,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -1063,6 +1125,18 @@ "url": "https://github.com/sponsors/jaredhanson" } }, + "node_modules/passport-custom": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/passport-custom/-/passport-custom-1.1.1.tgz", + "integrity": "sha512-/2m7jUGxmCYvoqenLB9UrmkCgPt64h8ZtV+UtuQklZ/Tn1NpKBeOorCYkB/8lMRoiZ5hUrCoMmDtxCS/d38mlg==", + "license": "MIT", + "dependencies": { + "passport-strategy": "1.x.x" + }, + "engines": { + "node": ">= 0.10.0" + } + }, "node_modules/passport-google-oauth20": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-2.0.0.tgz", @@ -1103,6 +1177,16 @@ "node": ">= 0.4.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1345,6 +1429,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -1545,6 +1652,22 @@ "node": ">= 0.8" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/auth-service/package.json b/auth-service/package.json index 14d0810..2d95f65 100644 --- a/auth-service/package.json +++ b/auth-service/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "dev": "nodemon server.js" + "dev": "dotenv -e .env.development nodemon server.js" }, "keywords": [], "author": "", @@ -17,6 +17,10 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0", + "passport-custom": "^1.1.1", "passport-google-oauth20": "^2.0.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/auth-service/passport.js b/auth-service/passport.js index e65e7c8..2f32e34 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -1,36 +1,51 @@ -require('dotenv').config(); +require("dotenv").config(); const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); +const CustomStrategy = require("passport-custom").Strategy; passport.use( - new GoogleStrategy( - { - clientID: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - callbackURL: process.env.GOOGLE_CALLBACK_URL, - scope: ["profile", "email"], - }, - function (accessToken, refreshToken, profile, callback) { + new GoogleStrategy( + { + clientID: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET, + callbackURL: process.env.GOOGLE_CALLBACK_URL, + scope: ["profile", "email"], + }, + function (accessToken, refreshToken, profile, callback) { + callback(null, profile); + } + ) +); - // Save the user info to your DB here if still not yet saved - // Example of what profile might contain: - // { - // "id": "112233445566778899", - // "displayName": "John Doe", - // "emails": [{ "value": "john.doe@gmail.com" }], - // "photos": [{ "value": "https://.../photo.jpg" }] - // } +passport.use( + "student-auth", + new CustomStrategy(async (req, done) => { + const { assignment, password } = req.body; - callback(null, profile); - } - ) + try { + // Call your external auth service + const response = await axios.post("http://localhost:8082/student/verify", { + assignment, + password, + }); + + if (response.data && response.data.success) { + const user = response.data.user; + return done(null, user); // success + } else { + return done(null, false, { message: "Invalid credentials" }); + } + } catch (err) { + return done(err); + } + }) ); passport.serializeUser((user, done) => { - done(null, user); + done(null, user); }); passport.deserializeUser((user, done) => { - done(null,user); -}); \ No newline at end of file + done(null, user); +}); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 782d09c..3c8e9de 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -52,6 +52,16 @@ router.get("/login/failed", (req, res) => { router.get("/google", passport.authenticate("google", ["profile", "email"])); +router.post("/student/login", (req, res) => { + passport.authenticate("student-auth"), + (req, res) => { + res.json({ + message: "Authenticated via external service", + user: req.user, + }); + }; +}); + router.get("/logout", (req, res) => { req.logOut(); res.redirect(process.env.LOGIN_REDIRECT_URL); diff --git a/uploader-service/app.js b/uploader-service/app.js index 6d71209..453324c 100644 --- a/uploader-service/app.js +++ b/uploader-service/app.js @@ -102,7 +102,7 @@ app.post('/machines/get', async (req, res) => { // Endpoint to upload files to Google Drive app.post('/drive/upload', upload.fields([{ name: 'pythonFile' }, { name: 'jsonFile', maxCount: 1 }]), async (req, res) => { const { folderLink } = req.body; - const { pythonFile, jsonFile } = req.files; + const { pythonFile, jsonFile } = req.files; if (!folderLink || !pythonFile) { return res.status(400).json({ error: 'Folder link and Python file are required' }); From adb005ae33965ff5dc5c7ea03704de11cf9db0e5 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 15:06:00 -0700 Subject: [PATCH 3/5] working logout and student login --- assignment-service/routes/StudentRouter.js | 11 ++++- auth-service/.env.development | 2 +- auth-service/passport.js | 50 ++++++++++++++++------ auth-service/routes/auth.js | 48 +++++++++++++++++---- auth-service/server.js | 7 +++ 5 files changed, 94 insertions(+), 24 deletions(-) diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index a84b271..6dcf37b 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -10,10 +10,12 @@ studentRouter.post("/save", (req, res) => {}); studentRouter.post("/deploy", (req, res) => {}); -studentRouter.post("/verify/", async (req, res) => { +studentRouter.post("/verify", async (req, res) => { try { - const assignmentId = req.body.id; + const assignmentId = req.body.assignmentId; const password = req.body.password; + console.log("Received request to verify assignment."); + console.log("Request body:", req.body); console.log( "Accessing assignment with ID:", assignmentId, @@ -35,13 +37,18 @@ studentRouter.post("/verify/", async (req, res) => { response.data.passwordhash ); + console.log("Password validation result:", isPasswordValid); + if (!isPasswordValid || !response.data) { + console.log("Invalid id or password."); return res.status(401).json({ error: "Invalid id and password" }); } + console.log("Verification successful. Sending response."); res.status(response.status).json(response.data); } catch (error) { console.error("Error fetching assignment details:", error.message); + console.error("Error details:", error); res.status(error.response?.status || 500).json({ error: error.message }); } }); diff --git a/auth-service/.env.development b/auth-service/.env.development index 74b17a1..91cdcab 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -5,6 +5,6 @@ GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" LOGIN_REDIRECT_URL="http://localhost:5173/" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -DB_USER_SERVICE_URL="http://js-user-db-service:3100/" +DB_USER_SERVICE_URL="http://localhost:3100/" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" PORT=8080 \ No newline at end of file diff --git a/auth-service/passport.js b/auth-service/passport.js index 2f32e34..1b6b835 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -3,6 +3,7 @@ require("dotenv").config(); const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); const CustomStrategy = require("passport-custom").Strategy; +const axios = require("axios"); passport.use( new GoogleStrategy( @@ -13,7 +14,7 @@ passport.use( scope: ["profile", "email"], }, function (accessToken, refreshToken, profile, callback) { - callback(null, profile); + callback(null, {...profile, role: "instructor"}); } ) ); @@ -21,31 +22,56 @@ passport.use( passport.use( "student-auth", new CustomStrategy(async (req, done) => { - const { assignment, password } = req.body; + const { assignmentId, password } = req.body; + + console.log("Custom strategy invoked"); + console.log("Received assignmentId:", assignmentId); + console.log("Received password:", password); try { - // Call your external auth service - const response = await axios.post("http://localhost:8082/student/verify", { - assignment, - password, - }); + console.log("Sending request to external auth service..."); + const response = await axios.post( + "http://localhost:8082/student/verify", + { + assignmentId, + password, + } + ); - if (response.data && response.data.success) { - const user = response.data.user; + if (response.status === 200 && response.data) { + user = { + ...response.data, + role: "student", + }; + console.log("Authentication successful, user:", user); return done(null, user); // success } else { + console.log("Authentication failed: Invalid credentials"); return done(null, false, { message: "Invalid credentials" }); } } catch (err) { + console.error("Error during authentication:", err); return done(err); } }) ); passport.serializeUser((user, done) => { - done(null, user); + // done(null, user); + console.log("Serializing user:", user); + done(null, { + id: user.assignmentid || user.emal, + displayName: user.studentname || user.displayName, + role: user.role, + }); }); -passport.deserializeUser((user, done) => { - done(null, user); +passport.deserializeUser(async (user, done) => { + try { + console.log("Deserializing user:", user); + done(null, user); + } catch (err) { + console.error("Error during deserialization:", err); + done(err); + } }); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 3c8e9de..47e848b 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -11,6 +11,8 @@ router.get( ); router.get("/current_user", (req, res) => { + console.log("Current user endpoint hit"); + console.log("Request user:", req.user); if (req.isAuthenticated()) { console.log("Authenticated user:", req.user); res.json(req.user); @@ -52,19 +54,47 @@ router.get("/login/failed", (req, res) => { router.get("/google", passport.authenticate("google", ["profile", "email"])); -router.post("/student/login", (req, res) => { +router.post( + "/student/login", passport.authenticate("student-auth"), - (req, res) => { - res.json({ - message: "Authenticated via external service", - user: req.user, + (req, res) => { + console.log("Student login endpoint hit"); + + if (req.user) { + console.log("Authenticated user:", req.user); + console.log("Processing student login..."); + + // Optional: augment user object (doesn't affect session unless you reserialize) + req.user.userId = req.user.assignmentid; + req.user.role = "student"; + + req.logIn(req.user, function(err) { + if (err) return next(err); + + console.log('is authenticated?: ' + req.isAuthenticated()); + + return res.json({ + success: true, + message: 'Successful Login', + user: req.user + }); }); - }; -}); + + } else { + console.log("Authentication failed"); + res.status(401).json({ error: true, message: "Authentication failed" }); + } + } +); router.get("/logout", (req, res) => { - req.logOut(); - res.redirect(process.env.LOGIN_REDIRECT_URL); + + req.logout((err) => { + if (err) { + return next(err); + } + res.redirect(process.env.LOGIN_REDIRECT_URL); + }); }); module.exports = router; diff --git a/auth-service/server.js b/auth-service/server.js index 8e92dce..f9ac814 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -6,10 +6,14 @@ const passport = require("passport"); const passportSetup = require("./passport"); const authRoute = require("./routes/auth"); const session = require("express-session"); +const bodyParser = require("body-parser"); const app = express(); +app.use(bodyParser.json()); // or express.json() +app.use(bodyParser.urlencoded({ extended: true })); app.use( + session({ secret: process.env.AUTH_SESSION_KEY, resave: false, @@ -31,6 +35,9 @@ app.use( }) ) + +app.use(express.json()); + app.use("/auth", authRoute); const port = process.env.PORT || 8080; From b3dcec17c0fb7d4f3b5263d604343f8aef214b93 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 17:19:47 -0700 Subject: [PATCH 4/5] bug fix for login via google --- auth-service/passport.js | 3 ++- auth-service/routes/auth.js | 2 +- user-db-service/.env | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/auth-service/passport.js b/auth-service/passport.js index 1b6b835..1448a9d 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -60,9 +60,10 @@ passport.serializeUser((user, done) => { // done(null, user); console.log("Serializing user:", user); done(null, { - id: user.assignmentid || user.emal, + id: user.assignmentid || user.id, displayName: user.studentname || user.displayName, role: user.role, + emails: user.emails || "none", }); }); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 47e848b..05d5f63 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -73,7 +73,7 @@ router.post( console.log('is authenticated?: ' + req.isAuthenticated()); - return res.json({ + return res.status(200).json({ success: true, message: 'Successful Login', user: req.user diff --git a/user-db-service/.env b/user-db-service/.env index 3aaa685..52a3ca1 100644 --- a/user-db-service/.env +++ b/user-db-service/.env @@ -5,8 +5,8 @@ # See the documentation for all the connection string options: https://pris.ly/d/connection-strings #use this when testing local, remmber to run the proxy command -# DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" +DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" -DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" +# DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" # DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable -NODE_PORT=3000 +NODE_PORT=3100 From 0defbfea5a4dfff161f959fa8dd91eec0068217e Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 18:33:50 -0700 Subject: [PATCH 5/5] bug fix for fly server --- assignment-db-service/fly.toml | 35 ++++++++++++++++++++--------- assignment-service/.env | 1 + assignment-service/.env.development | 2 +- assignment-service/.env.test | 2 +- assignment-service/server.js | 2 +- auth-service/.env | 1 + auth-service/.env.development | 1 + auth-service/passport.js | 2 +- auth-service/server.js | 1 - user-db-service/fly.toml | 7 ++---- 10 files changed, 33 insertions(+), 21 deletions(-) diff --git a/assignment-db-service/fly.toml b/assignment-db-service/fly.toml index 18fc89d..4f08c1f 100644 --- a/assignment-db-service/fly.toml +++ b/assignment-db-service/fly.toml @@ -7,26 +7,39 @@ app = 'db-assignment-service' primary_region = 'sea' [build] +# Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset -[http_service] - internal_port = 3000 - force_https = true - auto_stop_machines = 'stop' - auto_start_machines = true - min_machines_running = 0 - processes = ['app'] +# Removed the [http_service] section to disable public HTTP/HTTPS access +# [http_service] +# internal_port = 3000 +# force_https = true +# auto_stop_machines = true +# auto_start_machines = true +# min_machines_running = 0 +# processes = ["app"] [[services]] - protocol = 'tcp' + protocol = "tcp" internal_port = 3000 - ports = [] + internal_only = true # Makes this service only accessible internally + auto_start_machines = true + auto_stop_machines = true + + # Removed public port exposure + # [[services.ports]] + # port = 80 + # handlers = ["http"] + + # [[services.ports]] + # port = 443 + # handlers = ["tls", "http"] [services.concurrency] - type = 'requests' + type = "requests" hard_limit = 1000 soft_limit = 500 [[vm]] memory = '1gb' - cpu_kind = 'shared' + cpu_kind = "shared" cpus = 1 diff --git a/assignment-service/.env b/assignment-service/.env index b948690..9cf3674 100644 --- a/assignment-service/.env +++ b/assignment-service/.env @@ -1,2 +1,3 @@ #DB_ASSIGNMENT_SERVICE_URL = "http://localhost:3000" DB_ASSIGNMENT_SERVICE_URL = "http://db-assignment-service.internal:3000" +NODE_PORT = 8080 \ No newline at end of file diff --git a/assignment-service/.env.development b/assignment-service/.env.development index 1bc73e5..b0a3aab 100644 --- a/assignment-service/.env.development +++ b/assignment-service/.env.development @@ -3,4 +3,4 @@ NODE_ENV=development DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -PORT=8082 \ No newline at end of file +NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test index d39a82f..8323fe9 100644 --- a/assignment-service/.env.test +++ b/assignment-service/.env.test @@ -3,4 +3,4 @@ NODE_ENV=development DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -PORT=8082 \ No newline at end of file +NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/server.js b/assignment-service/server.js index 875a189..354b1f4 100644 --- a/assignment-service/server.js +++ b/assignment-service/server.js @@ -39,5 +39,5 @@ app.use(cors()); app.use("/instructor", instructorRouter); app.use("/student", studentRouter); -const port = process.env.PORT || 8080; +const port = process.env.NODE_PORT || 8080; app.listen(port, () => console.log(`Listening on port ${port}...`)); \ No newline at end of file diff --git a/auth-service/.env b/auth-service/.env index 4fe65d0..a5e74f3 100644 --- a/auth-service/.env +++ b/auth-service/.env @@ -6,6 +6,7 @@ ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.f #DB_USER_SERVICE_URL = "http://localhost:3000/" DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/" AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ASSIGNMENT_SERVICE_URL="http://assignment-service.internal:8080" # fly secrets set GOOGLE_CALLBACK_URL=https://byte-camp-auth-service.fly.dev/auth/google/callback #fly secrets set GOOGLE_CLIENT_ID=485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=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 LOGIN_REDIRECT_URL=https://bytecamp-web.fly.dev/ DB_USER_SERVICE_URL=https://db-user-service.fly.dev:3000/ AUTH_SESSION_KEY=f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42 \ No newline at end of file diff --git a/auth-service/.env.development b/auth-service/.env.development index 91cdcab..e302c2f 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -5,6 +5,7 @@ GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" LOGIN_REDIRECT_URL="http://localhost:5173/" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +ASSIGNMENT_SERVICE_URL="http://localhost:8082/" DB_USER_SERVICE_URL="http://localhost:3100/" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" PORT=8080 \ No newline at end of file diff --git a/auth-service/passport.js b/auth-service/passport.js index 1448a9d..8ef091d 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -31,7 +31,7 @@ passport.use( try { console.log("Sending request to external auth service..."); const response = await axios.post( - "http://localhost:8082/student/verify", + `${process.env.ASSIGNMENT_SERVICE_URL}/student/verify`, { assignmentId, password, diff --git a/auth-service/server.js b/auth-service/server.js index f9ac814..924dfac 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -35,7 +35,6 @@ app.use( }) ) - app.use(express.json()); app.use("/auth", authRoute); diff --git a/user-db-service/fly.toml b/user-db-service/fly.toml index 07d92c2..30dbd0d 100644 --- a/user-db-service/fly.toml +++ b/user-db-service/fly.toml @@ -6,11 +6,6 @@ primary_region = "sea" [build] # Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset -#[env] - #NODE_ENV = "production" - #DATABASE_URL = "postgresql://user:password@hostname:port/dbname" - # you can also leave DATABASE_URL unset here and use secrets instead - # Removed the [http_service] section to disable public HTTP/HTTPS access # [http_service] # internal_port = 3000 @@ -24,6 +19,8 @@ primary_region = "sea" protocol = "tcp" internal_port = 3000 internal_only = true # Makes this service only accessible internally + auto_start_machines = true + auto_stop_machines = true # Removed public port exposure # [[services.ports]]