prisma #1

Merged
fred merged 4 commits from prisma into main 2025-08-15 20:52:39 +00:00
8 changed files with 32 additions and 40 deletions
Showing only changes of commit 866922e0f2 - Show all commits

6
.gitignore vendored
View file

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

View file

@ -1,25 +1,29 @@
const express = require("express"); const express = require("express");
const cors = require("cors");
const { PrismaClient } = require("@prisma/client"); const { PrismaClient } = require("@prisma/client");
const appRoutes = require("./routes/appRoutes"); const appRoutes = require("./routes/appRoutes");
const app = express(); const app = express();
const cors = require("cors"); const port = process.env.PORT || 3000;
const port = 3000;
// Middleware
app.use(cors());
app.use(express.json());
// Routes
app.use("/api", appRoutes);
// Prisma client initialization
const prisma = new PrismaClient(); 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}`); console.log(`Server is running on http://localhost:${port}`);
}); } catch (error) {
console.error("Error starting the server:", error);
}
}
process.on("SIGINT", async () => { process.on("SIGINT", async () => {
try { try {
@ -31,3 +35,7 @@ process.on("SIGINT", async () => {
process.exit(1); process.exit(1);
} }
}); });
startServer();
module.exports = { app, prisma };

View file

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

View file

@ -12,7 +12,7 @@ services:
ports: ports:
- "${DB_PORT}:5432" - "${DB_PORT}:5432"
volumes: volumes:
- ./postgres/db:/var/lib/postgresql/data - ./db:/var/lib/postgresql/data
backend: backend:
image: recipes_backend image: recipes_backend
container_name: recipes_backend_${ID} container_name: recipes_backend_${ID}
@ -41,5 +41,6 @@ services:
- "${FRONTEND_PORT}:80" - "${FRONTEND_PORT}:80"
volumes: volumes:
- ./frontend:/usr/src/app - ./frontend:/usr/src/app
- "$FRONTEND_BUILD_DIR:/usr/src/app/dist"
environment: environment:
- NODE_ENV=${NODE_ENV} - NODE_ENV=${NODE_ENV}

View file

@ -10,5 +10,4 @@ COPY . .
EXPOSE 80 EXPOSE 80
# CMD ["npm", "run", "$NODE_ENV"]
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"; import { useState, useEffect } from "react";
function RecipeIngredients() { function RecipeIngredients() {
const [recipeIngredients, setRecipeIngredients] = useState<Ingredient[]>([]); const [recipeIngredients, setRecipeIngredients] = useState<string[]>([]);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(true); 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="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"> <div className="recipes-grid grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-8">
{recipeIngredients.map((ing) => ( {recipeIngredients.map((ing, idx) => (
<li key={ing.id}>{ing.raw}</li> <li key={idx}>{ing}</li>
))} ))}
</div> </div>
</div> </div>

View file

@ -145,7 +145,7 @@ function RecipePage() {
Ingredients: Ingredients:
</h4> </h4>
<ul className="space-y-2"> <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"> <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="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> <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