From 34fb89dac506fdd28e3235881a3dc34a80e922da Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Thu, 4 Apr 2024 11:30:26 +0200 Subject: [PATCH] feat: add Dockerfile and custom nginx configuration --- Dockerfile | 30 ++++++++++++++++++++++++++++++ nginx.conf | 28 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..014f029 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Stage 1: Build the application +FROM node:lts AS builder + +RUN npm install -g pnpm + +WORKDIR /app + +COPY package*.json pnpm-*.yaml ./ + +RUN pnpm install + +COPY . . + +RUN pnpm run build + +# Stage 2: Serve the application using Nginx +FROM nginx:stable-alpine + +# Remove the default nginx.conf +RUN rm /etc/nginx/conf.d/default.conf + +# Copy custom nginx configuration +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +# Copy build artifacts from the builder stage +COPY --from=builder /app/dist /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6da398b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,28 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + # Error 404 + error_page 404 /404.html; + + # General headers applied to all routes + add_header X-Frame-Options "DENY"; + add_header X-XSS-Protection "1; mode=block"; + add_header X-Content-Type-Options "nosniff"; + add_header Referrer-Policy "no-referrer-when-downgrade"; + add_header Permissions-Policy "interest-cohort=()"; + + # Special handling for /sw.js + location = /sw.js { + add_header cache-control "max-age=0, no-cache, no-store, must-revalidate"; + } + + # Handling missing pages + try_files $uri $uri/ /index.html; +}