From 866922e0f284a5fc780111cff6de85b3493bb168 Mon Sep 17 00:00:00 2001 From: fred Date: Fri, 15 Aug 2025 10:04:51 -0700 Subject: [PATCH] cleanup --- .gitignore | 6 ++-- backend/src/index.js | 38 ++++++++++++++---------- backend/src/middleware/auth.js | 1 - docker-compose.yaml | 3 +- frontend/Dockerfile | 1 - frontend/src/pages/RecipeIngredients.tsx | 6 ++-- frontend/src/pages/RecipePage.tsx | 2 +- postgres/docker-compose.yaml | 15 ---------- 8 files changed, 32 insertions(+), 40 deletions(-) delete mode 100644 backend/src/middleware/auth.js delete mode 100644 postgres/docker-compose.yaml diff --git a/.gitignore b/.gitignore index daee295..2abc4c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -examp_frontend/ -postgres/db +db/ */.env -.env +.env* todo sqldumps/ logs/ +dist/ diff --git a/backend/src/index.js b/backend/src/index.js index 9b9fef9..1b914be 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1,25 +1,29 @@ const express = require("express"); +const cors = require("cors"); const { PrismaClient } = require("@prisma/client"); const appRoutes = require("./routes/appRoutes"); + const app = express(); -const cors = require("cors"); -const port = 3000; - -// Middleware -app.use(cors()); -app.use(express.json()); - -// Routes -app.use("/api", appRoutes); - -// Prisma client initialization +const port = process.env.PORT || 3000; const prisma = new PrismaClient(); -module.exports = { app, prisma }; +function setupMiddleware(app) { + app.use(cors()); + app.use(express.json()); + app.use("/api", appRoutes); +} -app.listen(port, () => { - console.log(`Server is running on http://localhost:${port}`); -}); +setupMiddleware(app); + +// Start server +async function startServer() { + try { + app.listen(port); + console.log(`Server is running on http://localhost:${port}`); + } catch (error) { + console.error("Error starting the server:", error); + } +} process.on("SIGINT", async () => { try { @@ -31,3 +35,7 @@ process.on("SIGINT", async () => { process.exit(1); } }); + +startServer(); + +module.exports = { app, prisma }; diff --git a/backend/src/middleware/auth.js b/backend/src/middleware/auth.js deleted file mode 100644 index 65b3dba..0000000 --- a/backend/src/middleware/auth.js +++ /dev/null @@ -1 +0,0 @@ -// todo diff --git a/docker-compose.yaml b/docker-compose.yaml index ebcb296..7bf2207 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,7 +12,7 @@ services: ports: - "${DB_PORT}:5432" volumes: - - ./postgres/db:/var/lib/postgresql/data + - ./db:/var/lib/postgresql/data backend: image: recipes_backend container_name: recipes_backend_${ID} @@ -41,5 +41,6 @@ services: - "${FRONTEND_PORT}:80" volumes: - ./frontend:/usr/src/app + - "$FRONTEND_BUILD_DIR:/usr/src/app/dist" environment: - NODE_ENV=${NODE_ENV} diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 56cf382..571a3b1 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -10,5 +10,4 @@ COPY . . EXPOSE 80 -# CMD ["npm", "run", "$NODE_ENV"] CMD npm run $NODE_ENV diff --git a/frontend/src/pages/RecipeIngredients.tsx b/frontend/src/pages/RecipeIngredients.tsx index fd290c3..d9c85e1 100644 --- a/frontend/src/pages/RecipeIngredients.tsx +++ b/frontend/src/pages/RecipeIngredients.tsx @@ -2,7 +2,7 @@ import { getRecipeIngredients } from "../services/frontendApi.js"; import { useState, useEffect } from "react"; function RecipeIngredients() { - const [recipeIngredients, setRecipeIngredients] = useState([]); + const [recipeIngredients, setRecipeIngredients] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); @@ -30,8 +30,8 @@ function RecipeIngredients() { ) : (
- {recipeIngredients.map((ing) => ( -
  • {ing.raw}
  • + {recipeIngredients.map((ing, idx) => ( +
  • {ing}
  • ))}
    diff --git a/frontend/src/pages/RecipePage.tsx b/frontend/src/pages/RecipePage.tsx index 4f42de4..9fd23ab 100644 --- a/frontend/src/pages/RecipePage.tsx +++ b/frontend/src/pages/RecipePage.tsx @@ -145,7 +145,7 @@ function RecipePage() { Ingredients:
      - {recipe.ingredients.map((ingredient: Ingredient, index) => ( + {recipe.ingredients.map((ingredient: string, index) => (
    • {ingredient} diff --git a/postgres/docker-compose.yaml b/postgres/docker-compose.yaml deleted file mode 100644 index 0e4eb1a..0000000 --- a/postgres/docker-compose.yaml +++ /dev/null @@ -1,15 +0,0 @@ -services: - db: - container_name: recipe_postgres - image: docker.io/library/postgres:17 - restart: always - env_file: - - .env - environment: - - POSTGRES_USER=${DB_USER} - - POSTGRES_PASSWORD=${DB_PASSWORD} - - POSTGRES_DB=${DB_NAME} - ports: - - "5432:5432" - volumes: - - ./db:/var/lib/postgresql/data