Files
flights_web/Dockerfile.react
T
gnezim 2e2c5c09ce
CI / ci (push) Failing after 30s
Deploy / build-and-deploy (push) Failing after 6s
Fix __ENV__ truncation; route API_BASE_URL through the same injection
Two gaps blocked http://flights-ui.devwebzavod.ru/ru/flights-map:

1. The inline <script>window.__ENV__=...</script> was written with the
   Leaflet tile template ('/map/api/tile/{z}/{x}/{y}.jpeg') embedded
   directly. Rspack's html-plugin pre-processes the children string and
   ate the '{z}' placeholder, truncating the injected JS literal to
   '/map/api/tile/{z' — MAP_TILE_URL on the client ended up broken and
   getEnv() fell back to the default.

   Escape every '{'/'}' inside the stringified value as '\u007B'/'\u007D'.
   JS decodes the Unicode escapes back to '{}' at parse time; the html
   plugin's template engine sees no placeholders to eat. Object-literal
   braces outside the string stay raw (Unicode escapes aren't valid in
   operator positions in JS source).

2. API_BASE_URL was still hard-defaulting to 'http://localhost:8080/api',
   so every dictionary fetch on the deployed cluster died with
   ERR_CONNECTION_REFUSED. Thread API_BASE_URL through the same
   PUBLIC_ENV_KEYS/html.tags path as MAP_TILE_URL, add matching Docker
   ARG/ENV, and forward it in deployment/build-docker.sh + k8s manifest.

The devwebzavod default for both is https://flights.test.aeroflot.ru
— where the real Aeroflot ingress terminates /map/api/** and /api/**.
Prod keeps overriding with same-origin URLs.
2026-04-18 23:56:28 +03:00

51 lines
1.4 KiB
React

# Dockerfile.react Multi-stage build for Modern.js SSR standalone app.
# Coexists with the legacy ASP.NET Dockerfile.
FROM node:24-slim AS deps
WORKDIR /app
RUN corepack enable pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
FROM deps AS build
WORKDIR /app
COPY modern.config.ts module-federation.config.ts tsconfig.json ./
COPY src/ src/
# Modern.js publicDir: fonts, images, leaflet marker icons, favicons.
# Copied into dist/standalone/public/ at build time. Without this the
# /assets/** URLs resolve to the SPA index HTML (OTS font-parse failures,
# broken backgrounds, missing tile icons).
COPY config/ config/
# Runtime-tunable env vars. modern.config.ts reads these when Modern.js
# boots the SSR server at container start, so values set via k8s env
# propagate without a rebuild. The ARG line lets CI also bake a value
# into the image if the cluster can't set env at runtime.
ARG MAP_TILE_URL
ENV MAP_TILE_URL=${MAP_TILE_URL}
ARG API_BASE_URL
ENV API_BASE_URL=${API_BASE_URL}
RUN pnpm build:standalone
FROM node:24-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=8080
RUN corepack enable pnpm
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist/standalone/ ./dist/standalone/
COPY --from=build /app/src/ ./src/
COPY package.json modern.config.ts module-federation.config.ts ./
EXPOSE 8080
CMD ["pnpm", "exec", "modern", "serve"]