code cleanup
This commit is contained in:
parent
2a4621a1a9
commit
2ad8618dea
5 changed files with 18 additions and 89 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# fly.toml app configuration file generated for byte-camp-auth-service on 2025-04-21T14:38:25-07:00
|
||||
# fly.toml app configuration file generated for assignment-service on 2025-04-24T11:48:54-07:00
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
|
|
|||
56
assignment-service/package-lock.json
generated
56
assignment-service/package-lock.json
generated
|
|
@ -15,8 +15,7 @@
|
|||
"express": "^5.1.0",
|
||||
"express-session": "^1.18.1",
|
||||
"nodemon": "^3.1.9",
|
||||
"passport": "^0.7.0",
|
||||
"passport-google-oauth20": "^2.0.0"
|
||||
"passport": "^0.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
|
|
@ -68,15 +67,6 @@
|
|||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64url": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz",
|
||||
"integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/binary-extensions": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
||||
|
|
@ -979,12 +969,6 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/oauth": {
|
||||
"version": "0.10.2",
|
||||
"resolved": "https://registry.npmjs.org/oauth/-/oauth-0.10.2.tgz",
|
||||
"integrity": "sha512-JtFnB+8nxDEXgNyniwz573xxbKSOu3R8D40xQKqcjwJ2CDkYqUDI53o6IuzDJBx60Z8VKCm271+t8iFjakrl8Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
|
|
@ -1063,38 +1047,6 @@
|
|||
"url": "https://github.com/sponsors/jaredhanson"
|
||||
}
|
||||
},
|
||||
"node_modules/passport-google-oauth20": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-2.0.0.tgz",
|
||||
"integrity": "sha512-KSk6IJ15RoxuGq7D1UKK/8qKhNfzbLeLrG3gkLZ7p4A6DBCcv7xpyQwuXtWdpyR0+E0mwkpjY1VfPOhxQrKzdQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"passport-oauth2": "1.x.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/passport-oauth2": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.8.0.tgz",
|
||||
"integrity": "sha512-cjsQbOrXIDE4P8nNb3FQRCCmJJ/utnFKEz2NX209f7KOHPoX18gF7gBzBbLLsj2/je4KrgiwLLGjf0lm9rtTBA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64url": "3.x.x",
|
||||
"oauth": "0.10.x",
|
||||
"passport-strategy": "1.x.x",
|
||||
"uid2": "0.0.x",
|
||||
"utils-merge": "1.x.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jaredhanson"
|
||||
}
|
||||
},
|
||||
"node_modules/passport-strategy": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
|
||||
|
|
@ -1506,12 +1458,6 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/uid2": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz",
|
||||
"integrity": "sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undefsafe": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
"dotenv": "^16.5.0",
|
||||
"express": "^5.1.0",
|
||||
"express-session": "^1.18.1",
|
||||
"nodemon": "^3.1.9"
|
||||
"nodemon": "^3.1.9",
|
||||
"passport": "^0.7.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,39 +2,45 @@ const intructorRouter = require("express").Router();
|
|||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
|
||||
const { DB_ASSIGNMENT_SERVICE_URL } = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000";
|
||||
|
||||
// This endpoint is for instructors to create a new assignment
|
||||
intructorRouter.post("/create", passport.authenticate("jwt", { session: false }), async (req, res) => {
|
||||
try {
|
||||
const response = await axios.post(`${process.env.DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body);
|
||||
const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// This endpoint is for instructors to get a list of assignments they have created
|
||||
intructorRouter.get("/list", passport.authenticate("jwt", { session: false }), async (req, res) => {
|
||||
try {
|
||||
const instructorId = req.user.id; // Assuming req.user contains the authenticated user
|
||||
const response = await axios.get(`${process.env.DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`);
|
||||
const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// This endpoint is for instructors to update an assignment
|
||||
intructorRouter.put("/update/:id", passport.authenticate("jwt", { session: false }), async (req, res) => {
|
||||
try {
|
||||
const assignmentId = req.params.id;
|
||||
const response = await axios.put(`${process.env.DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body);
|
||||
const response = await axios.put(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// This endpoint is for instructors to delete an assignment
|
||||
intructorRouter.delete("/delete/:id", passport.authenticate("jwt", { session: false }), async (req, res) => {
|
||||
try {
|
||||
const assignmentId = req.params.id;
|
||||
const response = await axios.delete(`${process.env.DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`);
|
||||
const response = await axios.delete(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
|
|
|
|||
|
|
@ -1,37 +1,13 @@
|
|||
require('dotenv').config();
|
||||
|
||||
const cors = require("cors");
|
||||
const express = require("express");
|
||||
const passport = require("passport");
|
||||
const passportSetup = require("./passport");
|
||||
const authRoute = require("./routes/auth");
|
||||
const session = require("express-session");
|
||||
const instructorRouter = require("./routes/InstructorRouter");
|
||||
const studentRouter = require("./routes/StudentRouter");
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
session({
|
||||
secret: process.env.AUTH_SESSION_KEY,
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: {
|
||||
maxAge: 24 * 60 * 60 * 1000, // 1 day
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session());
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin: "https://bytecamp-web.fly.dev",
|
||||
methods: "GET",
|
||||
credentials: true,
|
||||
})
|
||||
)
|
||||
|
||||
app.use("/auth", authRoute);
|
||||
app.use("/instructor", instructorRouter);
|
||||
app.use("/student", studentRouter);
|
||||
|
||||
const port = process.env.PORT || 8080;
|
||||
app.listen(port, () => console.log(`Listening on port ${port}...`));
|
||||
Loading…
Add table
Add a link
Reference in a new issue