This commit is contained in:
fred 2025-08-15 10:04:51 -07:00
parent 6169274fe1
commit 866922e0f2
8 changed files with 32 additions and 40 deletions

6
.gitignore vendored
View file

@ -1,7 +1,7 @@
examp_frontend/
postgres/db
db/
*/.env
.env
.env*
todo
sqldumps/
logs/
dist/

View file

@ -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, () => {
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 };

View file

@ -1 +0,0 @@
// todo

View file

@ -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}

View file

@ -10,5 +10,4 @@ COPY . .
EXPOSE 80
# CMD ["npm", "run", "$NODE_ENV"]
CMD npm run $NODE_ENV

View file

@ -2,7 +2,7 @@ import { getRecipeIngredients } from "../services/frontendApi.js";
import { useState, useEffect } from "react";
function RecipeIngredients() {
const [recipeIngredients, setRecipeIngredients] = useState<Ingredient[]>([]);
const [recipeIngredients, setRecipeIngredients] = useState<string[]>([]);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
@ -30,8 +30,8 @@ function RecipeIngredients() {
) : (
<div className="recipe-outer bg-amber-100 p-4 md:p-8 lg:p-12">
<div className="recipes-grid grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-8">
{recipeIngredients.map((ing) => (
<li key={ing.id}>{ing.raw}</li>
{recipeIngredients.map((ing, idx) => (
<li key={idx}>{ing}</li>
))}
</div>
</div>

View file

@ -145,7 +145,7 @@ function RecipePage() {
Ingredients:
</h4>
<ul className="space-y-2">
{recipe.ingredients.map((ingredient: Ingredient, index) => (
{recipe.ingredients.map((ingredient: string, index) => (
<li key={index} className="text-gray-700 flex items-start">
<span className="w-1.5 h-1.5 bg-amber-400 rounded-full mt-2 mr-3 flex-shrink-0"></span>
<span className="font-medium text-left">{ingredient}</span>

View file

@ -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