FROM node:22-alpine AS builder

WORKDIR /build

# Build full docs site from docs/ (MDX -> static)
COPY docs/ ./docs/
RUN npx --yes @litodocs/cli build -i docs -o /out --provider static --rendering static && \
    find /out -type f \( -name "*.html" -o -name "*.xml" \) -exec sed -i 's|https://docs.example.com|https://mudabbir.fly.dev|g' {} +

FROM nginx:alpine

WORKDIR /usr/share/nginx/html

# Serve generated docs site
COPY --from=builder /out/ ./

# Use a custom server block to avoid http downgrade redirects on slash normalization
COPY nginx/docs.conf /etc/nginx/conf.d/default.conf

# Keep installer scripts available from same domain
COPY installer/install.sh ./install.sh
COPY installer/install.ps1 ./install.ps1

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1
