diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index f0162d1..72930c9 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -10,28 +10,30 @@ studentRouter.post("/save", async (req, res) => { //get the app name and code and save the latest jupyter file in s3 bucket const { appName, code } = req.body; + console.log("Received save request for app:", appName); + const notebook = { cells: [ - { - cell_type: "code", - execution_count: null, - metadata: { - language: "python" - }, - outputs: [], - source: code.split('\n').map(line => line + '\n') - } + { + cell_type: "code", + execution_count: null, + metadata: { + language: "python" + }, + outputs: [], + source: code.split('\n').map(line => line + '\n') + } ], metadata: { - kernelspec: { - display_name: "Python 3", - language: "python", - name: "python3" - }, - language_info: { - name: "python", - version: "3.x" - } + kernelspec: { + display_name: "Python 3", + language: "python", + name: "python3" + }, + language_info: { + name: "python", + version: "3.x" + } }, nbformat: 4, nbformat_minor: 5 @@ -43,23 +45,25 @@ studentRouter.post("/save", async (req, res) => { const notebookName = `${Date.now()}-notebook.ipynb`; console.log("DEPLOY_API_URL:", DEPLOY_API_URL); + console.log("Uploading notebook:", notebookName, "to app:", appName); + await fetch(`${DEPLOY_API_URL}/${appName}/upload`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 }) + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 }) }) - .then((response) => { - if (!response.ok) throw new Error("Failed to save notebook"); - return response.json(); - }) - .then((data) => { - console.log("Notebook saved successfully:", data); - res.status(200).json(data); - }) - .catch((error) => { - console.error("Error saving notebook:", error.message); - res.status(500).json({ error: error.message }); - }); + .then((response) => { + if (!response.ok) throw new Error("Failed to save notebook"); + return response.json(); + }) + .then((data) => { + console.log("Notebook saved successfully:", data); + res.status(200).json(data); + }) + .catch((error) => { + console.error("Error saving notebook:", error.message); + res.status(500).json({ error: error.message }); + }); }); studentRouter.get("/assignment/:qrnum", (req, res) => { diff --git a/auth-service/routes/api.js b/auth-service/routes/api.js index 91be5b4..02cc8f9 100644 --- a/auth-service/routes/api.js +++ b/auth-service/routes/api.js @@ -3,20 +3,22 @@ const api = require("express").Router(); const ASSIGNMENT_SERVICE_URL = process.env.ASSIGNMENT_SERVICE_URL; -// rerout to asisgnment url -api.use((req, res, next) => { - console.log(`Proxying request to: ${ASSIGNMENT_SERVICE_URL} : original url : ${req.originalUrl}`); - next(); -}); - api.use( - '/', + '/', createProxyMiddleware({ target: ASSIGNMENT_SERVICE_URL, changeOrigin: true, + logLevel: 'debug', pathRewrite: { - '^/api': '', // only remove /api + '^/api': '', // remove "/api" from the start }, + onProxyReq(proxyReq, req, res) { + console.log(`Proxying request to: ${ASSIGNMENT_SERVICE_URL}${req.url}`); + }, + onError(err, req, res) { + console.error('Proxy error:', err.message); + res.status(502).send('Bad Gateway: Failed to connect to target'); + } }) ); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 77193f1..8d06f8b 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -2,6 +2,13 @@ const auth = require("express").Router(); const passport = require("passport"); const axios = require("axios"); +const express = require("express"); + +const bodyParser = require("body-parser"); + +auth.use(express.json()); +auth.use(bodyParser.urlencoded({ extended: true })); + const AUTH_URL = process.env.AUTH_URL || "http://localhost:8080"; auth.get( diff --git a/auth-service/server.js b/auth-service/server.js index 18cdb72..ce39321 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -7,11 +7,8 @@ const passportSetup = require("./passport"); const authRoute = require("./routes/auth"); const apiRoute = require("./routes/api"); const session = require("express-session"); -const bodyParser = require("body-parser"); const app = express(); -app.use(express.json()); -app.use(bodyParser.urlencoded({ extended: true })); // console.log("AUTH_URL:", process.env.AUTH_URL); const isProduction = process.env.NODE_ENV === "production";