A
This commit is contained in:
parent
6d4e324a93
commit
2a4621a1a9
9 changed files with 1807 additions and 0 deletions
40
assignment-service/.dockerignore
Normal file
40
assignment-service/.dockerignore
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Node.js specific
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
yarn-debug.log
|
||||
|
||||
# Environment and secrets
|
||||
.env*
|
||||
*.env
|
||||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
|
||||
# Development artifacts
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
dist/
|
||||
build/
|
||||
out/
|
||||
|
||||
# Version control
|
||||
.git/
|
||||
.gitignore
|
||||
|
||||
# Temporary files
|
||||
tmp/
|
||||
temp/
|
||||
*.tmp
|
||||
|
||||
# Documentation
|
||||
*.md
|
||||
README*
|
||||
|
||||
# Docker files
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
|
||||
# Project-specific
|
||||
package-lock.json
|
||||
23
assignment-service/Dockerfile
Normal file
23
assignment-service/Dockerfile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Use the official Node.js image as the base image
|
||||
ARG NODE_VERSION=22.13.1
|
||||
FROM node:${NODE_VERSION}-slim AS base
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
RUN npm install
|
||||
|
||||
# Install dependencies using npm ci for deterministic builds
|
||||
# RUN --mount=type=cache,target=/root/.npm npm ci --production
|
||||
|
||||
# Copy the application source code
|
||||
COPY --link . .
|
||||
|
||||
# Expose the application port
|
||||
EXPOSE 8080
|
||||
|
||||
# Define the command to run the application
|
||||
CMD ["node", "server.js"]
|
||||
33
assignment-service/README.md
Normal file
33
assignment-service/README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Running the Project with Docker
|
||||
|
||||
This section provides instructions to build and run the project using Docker.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Ensure Docker and Docker Compose are installed on your system.
|
||||
- The project requires Node.js version `22.13.1` as specified in the Dockerfile.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- If applicable, create a `.env` file in the project root directory to define environment variables. Uncomment the `env_file` line in the `docker-compose.yml` file to enable this.
|
||||
|
||||
## Build and Run Instructions
|
||||
|
||||
1. Build the Docker image and start the services:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
2. Access the application at `http://localhost:8080`.
|
||||
|
||||
## Configuration
|
||||
|
||||
- The application runs with a non-root user for enhanced security.
|
||||
- The `NODE_ENV` is set to `production` and `NODE_OPTIONS` is configured for optimized memory usage.
|
||||
|
||||
## Exposed Ports
|
||||
|
||||
- The application service exposes port `8080` to the host system.
|
||||
|
||||
For further details, refer to the provided `Dockerfile` and `docker-compose.yml` files.
|
||||
42
assignment-service/fly.toml
Normal file
42
assignment-service/fly.toml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# fly.toml app configuration file generated for byte-camp-auth-service on 2025-04-21T14:38:25-07:00
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
||||
app = 'assignment-service'
|
||||
primary_region = 'sea'
|
||||
|
||||
[build]
|
||||
|
||||
[env]
|
||||
PORT = '8080'
|
||||
|
||||
[http_service]
|
||||
internal_port = 8080
|
||||
force_https = true
|
||||
auto_stop_machines = 'stop'
|
||||
auto_start_machines = true
|
||||
min_machines_running = 0
|
||||
processes = ['app']
|
||||
|
||||
[[services]]
|
||||
protocol = 'tcp'
|
||||
internal_port = 8080
|
||||
|
||||
[[services.ports]]
|
||||
port = 80
|
||||
handlers = ['http']
|
||||
|
||||
[[services.ports]]
|
||||
port = 443
|
||||
handlers = ['tls', 'http']
|
||||
|
||||
[[services.tcp_checks]]
|
||||
interval = '10s'
|
||||
timeout = '2s'
|
||||
grace_period = '5s'
|
||||
|
||||
[[vm]]
|
||||
memory = '1gb'
|
||||
cpu_kind = 'shared'
|
||||
cpus = 1
|
||||
1555
assignment-service/package-lock.json
generated
Normal file
1555
assignment-service/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
20
assignment-service/package.json
Normal file
20
assignment-service/package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "auth-service",
|
||||
"version": "1.0.0",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"axios": "^1.8.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
"express": "^5.1.0",
|
||||
"express-session": "^1.18.1",
|
||||
"nodemon": "^3.1.9"
|
||||
}
|
||||
}
|
||||
44
assignment-service/routes/InstructorRouter.js
Normal file
44
assignment-service/routes/InstructorRouter.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
const intructorRouter = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
|
||||
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);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
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}`);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
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}`);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = intructorRouter;
|
||||
13
assignment-service/routes/StudentRouter.js
Normal file
13
assignment-service/routes/StudentRouter.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const studentRouter = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
|
||||
studentRouter.post("/save", (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
studentRouter.post("/deploy", (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
module.exports = studentRouter;
|
||||
37
assignment-service/server.js
Normal file
37
assignment-service/server.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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 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);
|
||||
|
||||
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