Merge pull request #24 from JBB0807/deployment-prep

bug fix for saving and restarting notebook
This commit is contained in:
JB Balahadia 2025-05-21 10:58:39 -07:00 committed by GitHub
commit 1ebe18b1e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 54 additions and 44 deletions

View file

@ -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) => {

View file

@ -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');
}
})
);

View file

@ -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(

View file

@ -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";