From da2aea70ac88eef7991834d759da77a4ca765961 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Wed, 5 Mar 2025 18:19:08 -0700 Subject: [PATCH] FEAT: Docker for backend is working, just need to use docker compose to create a working application. --- backend/Dockerfile | 31 +++++++++++++++++++++++++++++++ backend/src/server.ts | 9 ++++----- 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 backend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..d4552d7 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,31 @@ +# Use a Node.js base image +FROM node:18-alpine + +# Set the working directory in the container +WORKDIR /app + +# Copy package.json and package-lock.json (or yarn.lock) +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the backend code +COPY . . + +# Expose the port your Express app runs on (internally only) +EXPOSE 5000 + +# Build the application +RUN npm run build + +# Start the application +CMD ["npm", "run", "start"] + +# BUILD COMMAND, from the ./backend directory +# docker build -t azpect3120/file.gophernest.backend:latest . + +# RUN COMMAND, from the ./backend directory +# The directory only matters because of the .env file +# docker run -p 5000:5000 --env-file .env -v /home/azpect:/home/azpect azpect3120/file.gophernest.backend:latest + diff --git a/backend/src/server.ts b/backend/src/server.ts index f5dfede..88520cd 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -8,9 +8,8 @@ import cors from "cors"; import archiver from "archiver"; import {appendDirectoryToArchive, appendFileToArchive} from "./download"; import path from "node:path"; -import jwt from "jsonwebtoken"; -import {config} from "dotenv"; import {verifyToken} from "./authenicate"; +import jwt from "jsonwebtoken"; /** * App details @@ -23,10 +22,10 @@ const ROOT: string = "/home/azpect"; * Configure the .env file, this is for testing only * TODO: Remove this */ -config({path: ".env"}); +// config({path: ".env"}); /** - * Invalid file extentions for the file editor. + * Invalid file extensions for the file editor. */ const INVALID_EXTS: string[] = ["exe", "dll", "obj", "lib", "bin", "dat", "pdf", "jpg", "jpeg", "png", "gif", "webm", "webp", "bmp", "mp3", "wav", "mp4", "avi", "zip", "rar", "7z", "iso", "dmg", "class", "pyc", "o", "a", "woff", "woff2", "ttf", "otf", "db", "sqlite", "mdb", "accdb", "psd", "ai", "indd", "blend", "fbx", "unitypackage", "pak", "sav", "msi", ".doc", ".docx", ".dot", ".dotx", ".docm", ".dotm", ".rtf", ".txt", ".xls", ".xlsx", ".xlsm", ".xltx", ".xltm", ".csv", ".ppt", ".pptx", ".pptm", ".potx", ".potm", ".ppsx", ".ppsm", ".mdb", ".accdb", ".accde", ".accdt", ".pst", ".ost", ".msg", ".one", ".onetoc2", ".pub", ".vsd", ".vsdx", ".vssx", ".vstx", ".odc", ".oft", ".pki"]; @@ -36,7 +35,7 @@ const INVALID_EXTS: string[] = ["exe", "dll", "obj", "lib", "bin", "dat", "pdf", */ const corsOptions: cors.CorsOptions = { origin: ["http://localhost:3100"], - methods: ["GET"] + methods: ["GET", "POST"] }; APP.use(cors(corsOptions));