diff --git a/Dockerfile.zeroemission b/Dockerfile.zeroemission new file mode 100644 index 0000000000..301f2b9b68 --- /dev/null +++ b/Dockerfile.zeroemission @@ -0,0 +1,32 @@ +# wegoze portal deployment (sub-path: /dashboards/laadpalen) +# Self-contained copy of ./Dockerfile with the base path baked in at build time. +# The standalone deployment keeps using ./Dockerfile and is unaffected. +# +# NEXT_PUBLIC_BASE_PATH is inlined at build time (Next.js), so every asset and +# data URL becomes /dashboards/laadpalen/... . `next start` re-reads next.config.ts at runtime, +# so the variable must be present there too. +FROM node:20-alpine AS deps +WORKDIR /app +COPY webapp/package.json webapp/package-lock.json ./ +RUN npm ci + +FROM node:20-alpine AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY webapp/ ./ +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_PUBLIC_BASE_PATH=/dashboards/laadpalen +RUN npm run build + +FROM node:20-alpine AS runner +WORKDIR /app +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_PUBLIC_BASE_PATH=/dashboards/laadpalen +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public +COPY --from=builder /app/next.config.ts ./next.config.ts +EXPOSE 3000 +CMD ["npm", "run", "start"] diff --git a/webapp/app/embed/page.tsx b/webapp/app/embed/page.tsx index 19bb78ef20..924c6c50ef 100644 --- a/webapp/app/embed/page.tsx +++ b/webapp/app/embed/page.tsx @@ -13,6 +13,7 @@ import { const MapDeck = dynamic(() => import("@/components/MapDeck"), { ssr: false }); const NL_BOUNDS: [number, number, number, number] = [3.31, 50.75, 7.21, 53.47]; +const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || ""; function EmbedInner() { const params = useSearchParams(); @@ -29,14 +30,14 @@ function EmbedInner() { const load = async () => { if (slug === "nederland") { const [p, f] = (await Promise.all([ - fetch("/data/nederland-passenger.geojson").then((r) => r.json()), - fetch("/data/nederland-freight.geojson").then((r) => r.json()), + fetch(`${BASE_PATH}/data/nederland-passenger.geojson`).then((r) => r.json()), + fetch(`${BASE_PATH}/data/nederland-freight.geojson`).then((r) => r.json()), ])) as CropoutData[]; if (cancelled) return; setChargeFeatures([...(p.features as ChargeFeature[]), ...(f.features as ChargeFeature[])]); setBounds(NL_BOUNDS); } else { - const crop = (await fetch(`/data/gemeenten/${slug}.geojson`).then((r) => r.json())) as CropoutData; + const crop = (await fetch(`${BASE_PATH}/data/gemeenten/${slug}.geojson`).then((r) => r.json())) as CropoutData; if (cancelled) return; setChargeFeatures(crop.features.filter((f) => f.properties.type === "charge") as ChargeFeature[]); setBoundaryFeatures(crop.features.filter((f) => f.properties.type === "boundary") as BoundaryFeature[]); diff --git a/webapp/app/page.tsx b/webapp/app/page.tsx index 85fb7907a3..57261b3650 100644 --- a/webapp/app/page.tsx +++ b/webapp/app/page.tsx @@ -34,6 +34,9 @@ const MapDeck = dynamic(() => import("@/components/MapDeck"), { }); const NL_BOUNDS: [number, number, number, number] = [3.31, 50.75, 7.21, 53.47]; +// Portal sub-path support: empty for the standalone deployment, set at build +// time for the wegoze portal (e.g. "/dashboards/laadpalen"). +const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || ""; const DEFAULT_SLUG = "utrecht"; export default function Home() { @@ -59,7 +62,7 @@ export default function Home() { // Load the analysis choropleth dataset once. useEffect(() => { - fetch("/data/derived/gemeente-metrics.geojson") + fetch(`${BASE_PATH}/data/derived/gemeente-metrics.geojson`) .then((r) => (r.ok ? r.json() : null)) .then((d: ChoroplethData | null) => d && setChoropleth(d)) .catch(() => {}); @@ -193,7 +196,7 @@ export default function Home() { // Load municipalities once. useEffect(() => { - fetch("/municipalities.json") + fetch(`${BASE_PATH}/municipalities.json`) .then((r) => r.json()) .then((data: Municipality[]) => { const sorted = data.sort((a, b) => { @@ -237,9 +240,9 @@ export default function Home() { const load = async () => { if (selectedMunicipality === "nederland") { const [pRes, fRes, provRes] = await Promise.all([ - fetch("/data/nederland-passenger.geojson"), - fetch("/data/nederland-freight.geojson"), - fetch("/data/provinces.geojson"), + fetch(`${BASE_PATH}/data/nederland-passenger.geojson`), + fetch(`${BASE_PATH}/data/nederland-freight.geojson`), + fetch(`${BASE_PATH}/data/provinces.geojson`), ]); const [p, f, prov] = (await Promise.all([pRes.json(), fRes.json(), provRes.json()])) as CropoutData[]; if (cancelled) return; @@ -253,9 +256,9 @@ export default function Home() { setGemeenteName("Nederland"); } else { const [cropRes, detRes, statusRes] = await Promise.all([ - fetch(`/data/gemeenten/${selectedMunicipality}.geojson`), - fetch(`/data/gemeenten/${selectedMunicipality}.details.json`), - fetch(`/data/status/${selectedMunicipality}.json`), + fetch(`${BASE_PATH}/data/gemeenten/${selectedMunicipality}.geojson`), + fetch(`${BASE_PATH}/data/gemeenten/${selectedMunicipality}.details.json`), + fetch(`${BASE_PATH}/data/status/${selectedMunicipality}.json`), ]); const crop = (await cropRes.json()) as CropoutData; const bundle = (await detRes.json()) as DetailBundle; diff --git a/webapp/components/AddressSearchInput.tsx b/webapp/components/AddressSearchInput.tsx index 4bbd91be02..330c6b83ba 100644 --- a/webapp/components/AddressSearchInput.tsx +++ b/webapp/components/AddressSearchInput.tsx @@ -84,6 +84,7 @@ export default function AddressSearchInput({ onAddressSelected, }: AddressSearchInputProps) { const [query, setQuery] = useState(''); + const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || ''; const [results, setResults] = useState([]); const [isLoading, setIsLoading] = useState(false); const [showDropdown, setShowDropdown] = useState(false); @@ -106,7 +107,7 @@ export default function AddressSearchInput({ try { const response = await fetch( - `/api/geocode?q=${encodeURIComponent(searchQuery)}` + `${BASE_PATH}/api/geocode?q=${encodeURIComponent(searchQuery)}` ); if (!response.ok) { @@ -152,7 +153,7 @@ export default function AddressSearchInput({ try { // Lookup full details for the selected address - const response = await fetch(`/api/geocode?id=${encodeURIComponent(result.id)}`); + const response = await fetch(`${BASE_PATH}/api/geocode?id=${encodeURIComponent(result.id)}`); if (!response.ok) { throw new Error('Address lookup failed'); diff --git a/webapp/next.config.ts b/webapp/next.config.ts index 9710bfb66f..315e3cf86d 100644 --- a/webapp/next.config.ts +++ b/webapp/next.config.ts @@ -3,8 +3,13 @@ import type { NextConfig } from "next"; // Basemap (CartoDB Positron via MapLibre) hosts used by the client. const MAP_TILE_HOSTS = "https://basemaps.cartocdn.com https://*.basemaps.cartocdn.com"; +// Opt-in sub-path support: empty for standalone/root deployments (unchanged), +// set to e.g. "/dashboards/laadpalen" at build time for the wegoze portal. +const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""; + const nextConfig: NextConfig = { compress: true, + ...(basePath ? { basePath } : {}), async headers() { const securityHeaders = [