Merge pull request #24 from JBB0807/deployment-prep
bug fix for saving and restarting notebook
This commit is contained in:
commit
1ebe18b1e8
4 changed files with 54 additions and 44 deletions
|
|
@ -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
|
//get the app name and code and save the latest jupyter file in s3 bucket
|
||||||
const { appName, code } = req.body;
|
const { appName, code } = req.body;
|
||||||
|
|
||||||
|
console.log("Received save request for app:", appName);
|
||||||
|
|
||||||
const notebook = {
|
const notebook = {
|
||||||
cells: [
|
cells: [
|
||||||
{
|
{
|
||||||
cell_type: "code",
|
cell_type: "code",
|
||||||
execution_count: null,
|
execution_count: null,
|
||||||
metadata: {
|
metadata: {
|
||||||
language: "python"
|
language: "python"
|
||||||
},
|
},
|
||||||
outputs: [],
|
outputs: [],
|
||||||
source: code.split('\n').map(line => line + '\n')
|
source: code.split('\n').map(line => line + '\n')
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
metadata: {
|
metadata: {
|
||||||
kernelspec: {
|
kernelspec: {
|
||||||
display_name: "Python 3",
|
display_name: "Python 3",
|
||||||
language: "python",
|
language: "python",
|
||||||
name: "python3"
|
name: "python3"
|
||||||
},
|
},
|
||||||
language_info: {
|
language_info: {
|
||||||
name: "python",
|
name: "python",
|
||||||
version: "3.x"
|
version: "3.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nbformat: 4,
|
nbformat: 4,
|
||||||
nbformat_minor: 5
|
nbformat_minor: 5
|
||||||
|
|
@ -43,23 +45,25 @@ studentRouter.post("/save", async (req, res) => {
|
||||||
|
|
||||||
const notebookName = `${Date.now()}-notebook.ipynb`;
|
const notebookName = `${Date.now()}-notebook.ipynb`;
|
||||||
console.log("DEPLOY_API_URL:", DEPLOY_API_URL);
|
console.log("DEPLOY_API_URL:", DEPLOY_API_URL);
|
||||||
|
console.log("Uploading notebook:", notebookName, "to app:", appName);
|
||||||
|
|
||||||
await fetch(`${DEPLOY_API_URL}/${appName}/upload`, {
|
await fetch(`${DEPLOY_API_URL}/${appName}/upload`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 })
|
body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 })
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) throw new Error("Failed to save notebook");
|
if (!response.ok) throw new Error("Failed to save notebook");
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log("Notebook saved successfully:", data);
|
console.log("Notebook saved successfully:", data);
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error saving notebook:", error.message);
|
console.error("Error saving notebook:", error.message);
|
||||||
res.status(500).json({ error: error.message });
|
res.status(500).json({ error: error.message });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
studentRouter.get("/assignment/:qrnum", (req, res) => {
|
studentRouter.get("/assignment/:qrnum", (req, res) => {
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,22 @@ const api = require("express").Router();
|
||||||
|
|
||||||
const ASSIGNMENT_SERVICE_URL = process.env.ASSIGNMENT_SERVICE_URL;
|
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(
|
api.use(
|
||||||
'/',
|
'/',
|
||||||
createProxyMiddleware({
|
createProxyMiddleware({
|
||||||
target: ASSIGNMENT_SERVICE_URL,
|
target: ASSIGNMENT_SERVICE_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
logLevel: 'debug',
|
||||||
pathRewrite: {
|
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');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@ const auth = require("express").Router();
|
||||||
const passport = require("passport");
|
const passport = require("passport");
|
||||||
const axios = require("axios");
|
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";
|
const AUTH_URL = process.env.AUTH_URL || "http://localhost:8080";
|
||||||
|
|
||||||
auth.get(
|
auth.get(
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,8 @@ const passportSetup = require("./passport");
|
||||||
const authRoute = require("./routes/auth");
|
const authRoute = require("./routes/auth");
|
||||||
const apiRoute = require("./routes/api");
|
const apiRoute = require("./routes/api");
|
||||||
const session = require("express-session");
|
const session = require("express-session");
|
||||||
const bodyParser = require("body-parser");
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
|
||||||
|
|
||||||
// console.log("AUTH_URL:", process.env.AUTH_URL);
|
// console.log("AUTH_URL:", process.env.AUTH_URL);
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
const isProduction = process.env.NODE_ENV === "production";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue