diff --git a/Dockerfile b/Dockerfile index 0a556c3..adfc140 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage -FROM node:20-alpine as build +FROM node:20-alpine AS build WORKDIR /app @@ -23,16 +23,23 @@ ENV VITE_APPWRITE_PROJECT_ID=$VITE_APPWRITE_PROJECT_ID # Build the app RUN npm run build -# Production stage -FROM nginx:alpine +# Production stage - lightweight Node.js server +FROM node:20-alpine -# Copy built files -COPY --from=build /app/dist /usr/share/nginx/html +WORKDIR /app -# Copy nginx config -COPY nginx.conf /etc/nginx/conf.d/default.conf +# Install serve globally +RUN npm install -g serve -# Expose port -EXPOSE 80 +# Copy built files from build stage +COPY --from=build /app/dist ./dist -CMD ["nginx", "-g", "daemon off;"] +# Run as non-root user for security +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 -G nodejs && \ + chown -R nodejs:nodejs /app + +USER nodejs + +# Start serve on port 3000 +CMD ["serve", "-s", "dist", "-l", "3000"] diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index c343cab..0000000 --- a/nginx.conf +++ /dev/null @@ -1,21 +0,0 @@ -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Gzip compression - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; - - # Handle SPA routing - redirect all requests to index.html - location / { - try_files $uri $uri/ /index.html; - } - - # Cache static assets - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - } -}