From 0b2453e5a9614d5caee69fe43dabe88f96997916 Mon Sep 17 00:00:00 2001 From: frakarr Date: Sun, 7 Dec 2025 20:29:36 +0100 Subject: [PATCH] feat: Implement Docker build and serving setup Adds Dockerfile for frontend and backend, along with Nginx configuration and .dockerignore files. This enables containerized deployment and proper handling of static assets and API proxying. Updates mockDb.ts to correctly type ticket attachments. --- .dockerignore | Bin 123 -> 136 bytes .dockerignore.txt | 11 +++++++++++ Dockerfile.txt | 15 +++++++++++++++ nginx.txt | 39 +++++++++++++++++++++++++++++++++++++++ server/Dockerfile.txt | 8 ++++++++ services/mockDb.ts | 4 ++-- 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .dockerignore.txt create mode 100644 Dockerfile.txt create mode 100644 nginx.txt create mode 100644 server/Dockerfile.txt diff --git a/.dockerignore b/.dockerignore index feecb7ce76f0eb8519a12fa6a453dac8f3d7e733..276bbec6497998dcc0f46046911191732494e1c2 100644 GIT binary patch delta 19 Zcmb>KV4P6R%cLHc!~K5$-Xb850{}^V2*CgV delta 5 McmeBRte#K}00q4Q5C8xG diff --git a/.dockerignore.txt b/.dockerignore.txt new file mode 100644 index 0000000..074c6d8 --- /dev/null +++ b/.dockerignore.txt @@ -0,0 +1,11 @@ + +node_modules +dist +.git +.env +.DS_Store +docker-compose.yml +Dockerfile +server/node_modules +.idea +.vscode diff --git a/Dockerfile.txt b/Dockerfile.txt new file mode 100644 index 0000000..4a58e6f --- /dev/null +++ b/Dockerfile.txt @@ -0,0 +1,15 @@ + +# Stage 1: Build Frontend +FROM node:18-alpine as build +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# Stage 2: Serve with Nginx +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/nginx.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.txt b/nginx.txt new file mode 100644 index 0000000..91a9aa8 --- /dev/null +++ b/nginx.txt @@ -0,0 +1,39 @@ + +worker_processes 1; + +events { worker_connections 1024; } + +http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + # Limite upload per allegati (es. foto/video ticket) + client_max_body_size 50M; + + server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + # Compressione Gzip + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + # Gestione SPA (React Router) + location / { + try_files $uri $uri/ /index.html; + } + + # Proxy API verso il backend + location /api/ { + proxy_pass http://backend:3001; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +} diff --git a/server/Dockerfile.txt b/server/Dockerfile.txt new file mode 100644 index 0000000..21b924d --- /dev/null +++ b/server/Dockerfile.txt @@ -0,0 +1,8 @@ + +FROM node:18-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm install --production +COPY . . +EXPOSE 3001 +CMD ["node", "server.js"] diff --git a/services/mockDb.ts b/services/mockDb.ts index a4e468a..c64af97 100644 --- a/services/mockDb.ts +++ b/services/mockDb.ts @@ -297,7 +297,7 @@ export const CondoService = { return request(url); }, - createTicket: async (data: Partial & { attachments?: { fileName: string, fileType: string, data: string }[] }) => { + createTicket: async (data: Omit, 'attachments'> & { attachments?: { fileName: string, fileType: string, data: string }[] }) => { const activeId = CondoService.getActiveCondoId(); if(!activeId) throw new Error("No active condo"); return request('/tickets', { @@ -325,4 +325,4 @@ export const CondoService = { seedPayments: () => { // No-op in remote mode } -}; \ No newline at end of file +};