modified assignment-service/server.js
This commit is contained in:
parent
e92a5c96a6
commit
263e583f80
4 changed files with 407 additions and 529 deletions
|
|
@ -10,13 +10,20 @@ primary_region = 'sea'
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
PORT = '8080'
|
PORT = '8080'
|
||||||
|
FLY_ORG="personal"
|
||||||
|
COMMON_BUCKET="snakeapi-deployment-test-bucket"
|
||||||
|
AWS_ACCESS_KEY_ID="tid__NSmOVaGknqitaCySppZjqVTgJSdDFnFbWcQllkC_juHwkbQZO"
|
||||||
|
AWS_SECRET_ACCESS_KEY="tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz"
|
||||||
|
AWS_ENDPOINT_URL_S3="https://fly.storage.tigris.dev"
|
||||||
|
AWS_REGION="auto"
|
||||||
|
FLY_API_BASE_URL = "https://api.machines.dev/v1"
|
||||||
|
|
||||||
[http_service]
|
[http_service]
|
||||||
internal_port = 8080
|
internal_port = 8080
|
||||||
force_https = true
|
force_https = true
|
||||||
auto_stop_machines = 'stop'
|
auto_stop_machines = 'stop'
|
||||||
auto_start_machines = true
|
auto_start_machines = true
|
||||||
min_machines_running = 0
|
min_machines_running = 1
|
||||||
processes = ['app']
|
processes = ['app']
|
||||||
|
|
||||||
[[services]]
|
[[services]]
|
||||||
|
|
|
||||||
879
assignment-service/package-lock.json
generated
879
assignment-service/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -10,7 +10,8 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.8.4",
|
"aws-sdk": "^2.1692.0",
|
||||||
|
"axios": "^1.9.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,23 @@ const passport = require("passport");
|
||||||
const session = require("express-session");
|
const session = require("express-session");
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
const AWS = require("aws-sdk");
|
||||||
const instructorRouter = require("./routes/InstructorRouter");
|
const instructorRouter = require("./routes/InstructorRouter");
|
||||||
const studentRouter = require("./routes/StudentRouter");
|
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 app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
app.use(cors());
|
||||||
|
|
||||||
// app.use(
|
// app.use(
|
||||||
// session({
|
// session({
|
||||||
|
|
@ -32,10 +42,33 @@ app.use(express.urlencoded({ extended: true }));
|
||||||
// methods: ["GET", "POST"],
|
// methods: ["GET", "POST"],
|
||||||
// credentials: true,
|
// credentials: true,
|
||||||
// })
|
// })
|
||||||
// )
|
// );
|
||||||
|
|
||||||
app.use("/instructor", instructorRouter);
|
app.use("/instructor", instructorRouter);
|
||||||
app.use("/student", studentRouter);
|
app.use("/student", studentRouter);
|
||||||
|
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
res.send("OK");
|
||||||
|
});
|
||||||
|
|
||||||
|
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" });
|
||||||
|
}
|
||||||
|
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"));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load notebook:", error);
|
||||||
|
res.status(500).json({ error: "Failed to load notebook" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const port = process.env.PORT || 8080;
|
const port = process.env.PORT || 8080;
|
||||||
app.listen(port, () => console.log(`Listening on port ${port}...`));
|
app.listen(port, "0.0.0.0", () => console.log(`Listening on 0.0.0.0:${port}...`));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue