more bug fix, fix to run on fly.io
This commit is contained in:
parent
aded70ea0b
commit
330baa51ac
16 changed files with 529 additions and 150 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# fly.toml app configuration file generated for assignment-service on 2025-05-09T00:17:41-07:00
|
||||
# fly.toml app configuration file generated for assignment-service on 2025-05-20T12:51:18-07:00
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
|
@ -8,40 +8,19 @@ primary_region = 'sea'
|
|||
|
||||
[build]
|
||||
|
||||
[build]
|
||||
# Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset
|
||||
|
||||
# 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 = 8080
|
||||
internal_only = true # Makes this service only accessible internally
|
||||
auto_stop_machines = 'stop'
|
||||
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"]
|
||||
ports = [] # ✅ No public ports = no public IP
|
||||
|
||||
[services.concurrency]
|
||||
type = "requests"
|
||||
type = 'requests'
|
||||
hard_limit = 1000
|
||||
soft_limit = 500
|
||||
|
||||
[[vm]]
|
||||
memory = '1gb'
|
||||
cpu_kind = "shared"
|
||||
cpu_kind = 'shared'
|
||||
cpus = 1
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ studentRouter.post("/save", async (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
studentRouter.post("/deploy", (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
studentRouter.get("/assignment/:qrnum", (req, res) => {
|
||||
const qrnum = req.params.qrnum;
|
||||
console.log("Fetching details for qr number:", qrnum);
|
||||
|
|
|
|||
|
|
@ -3,19 +3,23 @@ const cors = require("cors");
|
|||
const passport = require("passport");
|
||||
const session = require("express-session");
|
||||
|
||||
const axios = require("axios");
|
||||
|
||||
const express = require("express");
|
||||
const AWS = require("aws-sdk");
|
||||
const instructorRouter = require("./routes/InstructorRouter");
|
||||
const studentRouter = require("./routes/StudentRouter");
|
||||
|
||||
const s3 = new AWS.S3({
|
||||
endpoint: process.env.AWS_ENDPOINT_URL_S3,
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
region: process.env.AWS_REGION,
|
||||
s3ForcePathStyle: true,
|
||||
});
|
||||
const BUCKET = process.env.COMMON_BUCKET;
|
||||
const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600";
|
||||
|
||||
// const s3 = new AWS.S3({
|
||||
// endpoint: process.env.AWS_ENDPOINT_URL_S3,
|
||||
// accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||
// secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
// region: process.env.AWS_REGION,
|
||||
// s3ForcePathStyle: true,
|
||||
// });
|
||||
// const BUCKET = process.env.COMMON_BUCKET;
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
|
@ -57,20 +61,17 @@ app.get("/notebook/save/:appname", async (req, res) => {
|
|||
app.get("/notebook/:appName", async (req, res) => {
|
||||
try {
|
||||
const { appName } = req.params;
|
||||
const prefix = `${appName}/notebooks/`;
|
||||
const list = await s3
|
||||
.listObjectsV2({ Bucket: BUCKET, Prefix: prefix })
|
||||
.promise();
|
||||
if (!list.Contents || list.Contents.length === 0) {
|
||||
return res.status(404).json({ error: "Notebook not found" });
|
||||
console.log(`Fetching notebook for appName: ${appName}`);
|
||||
|
||||
const response = await axios.get(`${DEPLOY_API_URL}/notebook/${appName}`);
|
||||
if (response.status !== 200) {
|
||||
console.log(`Failed to restart app for appName: ${appName}`);
|
||||
return res.status(500).json({ error: "Failed to restart app" });
|
||||
}
|
||||
const latest = list.Contents.reduce((prev, curr) =>
|
||||
prev.LastModified > curr.LastModified ? prev : curr
|
||||
);
|
||||
const data = await s3
|
||||
.getObject({ Bucket: BUCKET, Key: latest.Key })
|
||||
.promise();
|
||||
res.send(data.Body.toString("utf-8"));
|
||||
|
||||
console.log(`Notebook data received for appName: ${appName}`);
|
||||
res.status(200).json(response.data);
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to load notebook:", error);
|
||||
res.status(500).json({ error: "Failed to load notebook" });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue