Serve with Node/Express instead of nginx (matches working astroreal pattern)

- Add server.js: Express serves dist/ + injects env (GA_ID, FORM_EMAIL, GMAP) at runtime
- Container port now 4321 (identical to moreminimore-astroreal that deploys on EasyPanel)
- Remove nginx.conf + entrypoint.sh (no longer needed); Dockerfile uses node server.js
- Verified: pnpm build + node server.js -> all 40 pages serve 200, env injected, 0 leftovers
This commit is contained in:
2026-08-06 15:13:39 +07:00
parent a8fa17a947
commit 44c405730e
9 changed files with 713 additions and 182 deletions

View File

@@ -1,49 +1,27 @@
# =============================================================================
# มิตซูชัยพร สมุทรสาคร — Astro static site
# Multi-stage: 1) build with node + pnpm 2) serve dist with nginx.
# ── มิตซูชัยพร — Astro + Express (static) ─────────────────────────
# Build: pnpm build (astro) → Runtime: node server.js (port 4321)
#
# Env vars (GA_ID, FORM_EMAIL, GMAP_LAT/LNG) are injected into HTML by
# entrypoint.sh at container startup (see .env.example).
# Host on EasyPanel as a Dockerfile service, port 80.
# =============================================================================
# Mirrors moreminimore-astroreal deployment pattern that works on EasyPanel:
# serve the static Astro build from a small Node/Express server (no nginx).
#
# Env: PORT (default 4321), GA_ID, FORM_EMAIL, GMAP_LAT/LNG (see .env.example)
FROM node:22-bookworm-slim
# ---------- Stage 1: build Astro ----------
FROM node:22-alpine AS build
WORKDIR /app
# pnpm via corepack (uses the version pinned by packageManager / pnpm-workspace)
# Use pnpm 11 to match the pnpm-lock.yaml + allowBuilds schema from Astro v7.
RUN corepack enable && corepack prepare pnpm@11 --activate
# ── Dependencies (pnpm 11 to match lockfile) ─────────────────────
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && corepack prepare pnpm@11 --activate \
&& pnpm install --frozen-lockfile
# Install deps (uses pnpm-lock.yaml)
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
# Copy source + content
# ── Source + Build ───────────────────────────────────────────────
COPY astro.config.mjs tsconfig.json ./
COPY src/ src/
COPY public/ public/
# Build -> dist/
RUN pnpm build
# ---------- Stage 2: serve with nginx ----------
FROM nginx:1.27-alpine
# Remove default site
RUN rm -rf /usr/share/nginx/html/*
# Copy built site
COPY --from=build /app/dist/ /usr/share/nginx/html/
# nginx config + env-injecting entrypoint
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget -q -O /dev/null http://localhost/ || exit 1
ENTRYPOINT ["/entrypoint.sh"]
# ── Runtime ──────────────────────────────────────────────────────
COPY server.js ./
EXPOSE 4321
CMD ["node", "server.js"]