dockerize app
This commit is contained in:
parent
af99a9b4c2
commit
091a21c8e6
9 changed files with 78 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
examp_frontend/
|
||||
postgres/db
|
||||
*/.env
|
||||
.env
|
||||
todo
|
||||
|
|
13
backend/Dockerfile
Normal file
13
backend/Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
|||
FROM node:22
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
|
@ -1,6 +1,6 @@
|
|||
const express = require("express");
|
||||
const db = require("./db");
|
||||
const port = 6063;
|
||||
const port = 3000;
|
||||
const cors = require('cors'); // to remove cors origin error in dev TODO: remove when dockerized
|
||||
|
||||
const app = express();
|
||||
|
@ -8,7 +8,10 @@ app.use(cors()); // to remove cors origin error in dev TODO: remove when docker
|
|||
app.use(express.json());
|
||||
|
||||
// ####### ROUTES #######
|
||||
|
||||
app.get("/test", async (req, res) => {
|
||||
console.log('test')
|
||||
res.json({ test: 'test' })
|
||||
});
|
||||
// ### GET ALL RECIPES ###
|
||||
app.get("/recipes", async (req, res) => {
|
||||
try {
|
||||
|
|
|
@ -5,8 +5,8 @@ module.exports = {
|
|||
development: {
|
||||
client: 'postgresql',
|
||||
connection: {
|
||||
host: process.env.DB_HOST,
|
||||
port: process.env.DB_PORT,
|
||||
host: 'db',
|
||||
port: 5432,
|
||||
database: process.env.DB_NAME,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD
|
||||
|
|
38
docker-compose.yaml
Normal file
38
docker-compose.yaml
Normal file
|
@ -0,0 +1,38 @@
|
|||
services:
|
||||
db:
|
||||
container_name: recipes_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:
|
||||
- ./postgres/db:/var/lib/postgresql/data
|
||||
backend:
|
||||
image: recipes_backend
|
||||
container_name: recipes_backend
|
||||
build: ./backend
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./backend:/usr/src/app
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- DB_USER=${DB_USER}
|
||||
- DB_PASSWORD=${DB_PASSWORD}
|
||||
- DB_NAME=${DB_NAME}
|
||||
frontend:
|
||||
image: recipes_frontend
|
||||
container_name: recipes_frontend
|
||||
build: ./frontend
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./frontend:/usr/src/app
|
||||
environment:
|
||||
- NODE_ENV=development
|
13
frontend/Dockerfile
Normal file
13
frontend/Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
|||
FROM node:22
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
|
@ -4,7 +4,7 @@
|
|||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"dev": "vite --host --port 80",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
export const getRecipes = async () => {
|
||||
const response = await fetch("http://localhost:6063/recipes");
|
||||
const response = await fetch("http://localhost:3000/recipes");
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getRecipeById = async (id) => {
|
||||
const response = await fetch(`http://localhost:6063/recipe/${id}`);
|
||||
const response = await fetch(`http://localhost:3000/recipe/${id}`);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ export const getRecipeById = async (id) => {
|
|||
export const addRecipe = async (recipeData) => {
|
||||
console.log(JSON.stringify(recipeData))
|
||||
// return
|
||||
const response = await fetch("http://localhost:6063/add-recipe", {
|
||||
const response = await fetch("http://localhost:3000/add-recipe", {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(recipeData)
|
||||
|
@ -27,7 +27,7 @@ export const deleteRecipe = async (id) => {
|
|||
console.log('run delete')
|
||||
console.log(id)
|
||||
// return
|
||||
const response = await fetch("http://localhost:6063/delete-recipe", {
|
||||
const response = await fetch("http://localhost:3000/delete-recipe", {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id })
|
||||
|
|
|
@ -10,6 +10,6 @@ services:
|
|||
- POSTGRES_PASSWORD=${DB_PASSWORD}
|
||||
- POSTGRES_DB=${DB_NAME}
|
||||
ports:
|
||||
- "${DB_PORT}:5432"
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./db:/var/lib/postgresql/data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue