diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e5183..fc9c225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ +# [1.29.0](https://github.com/deployn/astro-deploy/compare/v1.28.0...v1.29.0) (2025-03-08) + + +### Features + +* add 404 page ([04cba4f](https://github.com/deployn/astro-deploy/commit/04cba4fa051b1c8958aa4dfe99266c56d0e8cf0b)) +* **blog:** add redirect to 404 page if entry is not found ([6cd32df](https://github.com/deployn/astro-deploy/commit/6cd32df0eeadad3094cc35724961a4bbd5541eb0)) +* **Dockerfile:** use Alpine base image and add healthcheck ([02e218d](https://github.com/deployn/astro-deploy/commit/02e218d1853c3c06d48bb3f8811564d910c61837)) + +# [1.29.0-beta.3](https://github.com/deployn/astro-deploy/compare/v1.29.0-beta.2...v1.29.0-beta.3) (2024-10-05) + + +### Features + +* **blog:** add redirect to 404 page if entry is not found ([6cd32df](https://github.com/deployn/astro-deploy/commit/6cd32df0eeadad3094cc35724961a4bbd5541eb0)) + +# [1.29.0-beta.2](https://github.com/deployn/astro-deploy/compare/v1.29.0-beta.1...v1.29.0-beta.2) (2024-10-05) + + +### Features + +* add 404 page ([04cba4f](https://github.com/deployn/astro-deploy/commit/04cba4fa051b1c8958aa4dfe99266c56d0e8cf0b)) + +# [1.29.0-beta.1](https://github.com/deployn/astro-deploy/compare/v1.28.0...v1.29.0-beta.1) (2024-10-04) + + +### Features + +* **Dockerfile:** use Alpine base image and add healthcheck ([02e218d](https://github.com/deployn/astro-deploy/commit/02e218d1853c3c06d48bb3f8811564d910c61837)) + # [1.28.0](https://github.com/deployn/astro-deploy/compare/v1.27.0...v1.28.0) (2024-09-13) diff --git a/Dockerfile b/Dockerfile index 8b82215..da275b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,15 @@ -FROM node:20-slim AS base +# Build Stage +FROM node:20-alpine AS build ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable WORKDIR /app + COPY package.json pnpm-lock.yaml ./ - -FROM base AS prod-deps -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile - -FROM base AS build-deps RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile -FROM build-deps AS build COPY . . ARG SITE_URL ENV SITE_URL=${SITE_URL} @@ -21,10 +17,21 @@ ARG DIRECTUS_URL ENV DIRECTUS_URL=${DIRECTUS_URL} RUN pnpm run build +# Runtime Stage FROM nginx:1.25-alpine AS runtime + +# Copy custom nginx config COPY nginx/nginx.conf /etc/nginx/nginx.conf + +# Copy built assets from build stage COPY --from=build /app/dist /usr/share/nginx/html +# Add curl for healthchecks +RUN apk add --no-cache curl + +# Healthcheck +HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/ || exit 1 + EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 6e7acb6..4e2f07b 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,26 +1,28 @@ user nginx; worker_processes auto; -error_log /var/log/nginx/error.log notice; -pid /var/run/nginx.pid; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; events { - worker_connections 1024; + worker_connections 1024; } http { - include /etc/nginx/mime.types; - default_type application/octet-stream; + include /etc/nginx/mime.types; + default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; + access_log /var/log/nginx/access.log main; - sendfile on; - - keepalive_timeout 65; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; gzip on; gzip_vary on; @@ -32,26 +34,33 @@ http { listen 80; listen [::]:80; server_name localhost; - port_in_redirect off; + root /usr/share/nginx/html; + index index.html index.htm; - root /usr/share/nginx/html; - index index.html index.htm; - rewrite ^([^.]*[^/])$ $1/ permanent; - try_files $uri $uri/ $uri/index.html =404; + location / { + try_files $uri $uri/ /index.html; + } - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp)$ { - expires 60d; + location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff|woff2|eot|ttf|webp)$ { + expires 30d; add_header Cache-Control "public, no-transform"; } + error_page 404 /404.html; + location = /404.html { + internal; + } + error_page 500 502 503 504 /50x.html; location = /50x.html { - root /usr/share/nginx/html; + internal; } add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; add_header X-XSS-Protection "1; mode=block"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + add_header Referrer-Policy "strict-origin-when-cross-origin"; + add_header Permissions-Policy "geolocation=(), microphone=(), camera=()"; } } diff --git a/package.json b/package.json index 8c912b4..d03f42a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "astro-deploy", "type": "module", - "version": "1.28.0", + "version": "1.29.0", "description": "A custom Astro.js template", "private": true, "scripts": { @@ -45,13 +45,13 @@ "alpinejs": "^3.14.1", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", - "commitizen": "^4.3.0", + "commitizen": "^4.3.1", "cz-conventional-changelog": "^3.3.0", "lucide-react": "^0.479.0", "pagefind": "^1.1.1", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", - "prettier-plugin-tailwindcss": "^0.6.6", + "prettier-plugin-tailwindcss": "^0.6.8", "pwa-asset-generator": "^6.3.2", "react": "^19.0.0", "react-dom": "^19.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4eced01..f268472 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -91,7 +91,7 @@ importers: specifier: ^2.1.1 version: 2.1.1 commitizen: - specifier: ^4.3.0 + specifier: ^4.3.1 version: 4.3.1(@types/node@22.13.9)(typescript@5.8.2) cz-conventional-changelog: specifier: ^3.3.0 @@ -109,7 +109,7 @@ importers: specifier: ^0.14.1 version: 0.14.1 prettier-plugin-tailwindcss: - specifier: ^0.6.6 + specifier: ^0.6.8 version: 0.6.11(prettier-plugin-astro@0.14.1)(prettier@3.5.3) pwa-asset-generator: specifier: ^6.3.2 diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..68e329d --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,12 @@ +--- +import BaseLayout from '@/layouts/BaseLayout.astro'; +--- + + +
+

404: Page Not Found

+

+ The page you are looking for does not exist. Please check the URL or return to the home page. +

+
+
diff --git a/src/pages/blog/[...page].astro b/src/pages/blog/[...page].astro index ab8df7f..7d67fef 100644 --- a/src/pages/blog/[...page].astro +++ b/src/pages/blog/[...page].astro @@ -110,14 +110,11 @@ const { {author.url ? ( + class="font-medium text-primary-600 underline hover:text-primary-500 dark:text-primary-400 dark:hover:text-primary-300"> {author.name} ) : ( - + {author.name} )} diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index a49565a..550292e 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -21,6 +21,11 @@ interface Props { } const { entry } = Astro.props as Props; + +if (!entry) { + return Astro.redirect('/404'); +} + const { Content } = await entry.render(); const components = { table: Table }; const {