diff options
| -rw-r--r-- | Dockerfile | 10 | ||||
| -rw-r--r-- | docker-entrypoint.sh | 12 | ||||
| -rw-r--r-- | esbuild.config.js | 11 |
3 files changed, 18 insertions, 15 deletions
@@ -1,8 +1,5 @@ FROM node:22-alpine AS builder -ARG HOST="adelie.liz.coffee" -ENV HOST=${HOST} - WORKDIR /app COPY package*.json ./ RUN npm ci @@ -13,12 +10,17 @@ RUN npm run build FROM nginx:alpine as adelie +ENV HOST=https://adelie.liz.coffee + COPY --from=builder /app/dist/ /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/nginx.conf +COPY docker-entrypoint.sh /docker-entrypoint.sh + +RUN chmod +x /docker-entrypoint.sh EXPOSE 80 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1 -CMD ["nginx", "-g", "daemon off;"] +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..123725b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Rewrite asset URLs in HTML to use the production domain +if [ -n "$HOST" ]; then + sed -i "s|href=\"/bundle\.|href=\"$HOST/bundle.|g" /usr/share/nginx/html/index.html + sed -i "s|src=\"/bundle\.|src=\"$HOST/bundle.|g" /usr/share/nginx/html/index.html + sed -i "s|href=\"/img/|href=\"$HOST/img/|g" /usr/share/nginx/html/index.html + sed -i "s|src=\"/oneko/|src=\"$HOST/oneko/|g" /usr/share/nginx/html/index.html +fi + +# Start nginx +exec nginx -g 'daemon off;' diff --git a/esbuild.config.js b/esbuild.config.js index 1bee10c..88d726a 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -39,17 +39,6 @@ async function copyAssets() { async function processHTML() { let html = await fs.readFile('src/index.html', 'utf8'); - - const host = process.env.HOST || ''; - const cleanHost = host.replace(/\/$/, ''); - - if (cleanHost) { - html = html.replace(/href="\/bundle\./g, `href="${cleanHost}/bundle.`); - html = html.replace(/src="\/bundle\./g, `src="${cleanHost}/bundle.`); - html = html.replace(/href="\/img\//g, `href="${cleanHost}/img/`); - html = html.replace(/src="\/oneko\//g, `src="${cleanHost}/oneko/`); - } - await fs.writeFile('dist/index.html', html); } |
