diff --git a/.github/workflows/deploy-front.yml b/.github/workflows/deploy-front.yml index 9cc6044..4b85da6 100644 --- a/.github/workflows/deploy-front.yml +++ b/.github/workflows/deploy-front.yml @@ -62,3 +62,11 @@ jobs: publish-profile: ${{ secrets.AZURE_FRONT_PUBLISH_PROFILE }} images: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} restart: true + + # Warm-up: force ISR regeneration so first real user gets data + - name: Warm-up (force ISR regeneration) + run: | + echo "Waiting for App Service to start..." + sleep 30 + curl -s -o /dev/null -w "%{http_code}" https://info-embalse-front-prod-ecguababcfdsepga.westeurope-01.azurewebsites.net/ + echo " - Warm-up done, ISR regeneration triggered" diff --git a/front/src/pods/embalse-search/embalse-search.repository.ts b/front/src/pods/embalse-search/embalse-search.repository.ts index e2d9156..b2b7817 100644 --- a/front/src/pods/embalse-search/embalse-search.repository.ts +++ b/front/src/pods/embalse-search/embalse-search.repository.ts @@ -4,27 +4,34 @@ import { getDb } from "@/lib/mongodb"; import type { Embalse } from "./api/api.model"; export async function getEmbalsesFromDb(): Promise { - const db = await getDb(); - const docs = await db - .collection("embalses") - .find( - {}, - { - projection: { - _id: 1, - nombre: 1, - provincia: 1, - slug: 1, + try { + const db = await getDb(); + const docs = await db + .collection("embalses") + .find( + {}, + { + projection: { + _id: 1, + nombre: 1, + provincia: 1, + slug: 1, + }, }, - }, - ) - .toArray(); + ) + .toArray(); - return docs.map((doc) => ({ - _id: doc.slug ?? createSlug(doc.nombre ?? ""), - nombre: doc.nombre ?? "", - provincia: doc.provincia ?? "", - })); + return docs.map((doc) => ({ + _id: doc.slug ?? createSlug(doc.nombre ?? ""), + nombre: doc.nombre ?? "", + provincia: doc.provincia ?? "", + })); + } catch { + console.warn( + "getEmbalsesFromDb: MongoDB not available (build time?), returning empty array" + ); + return []; + } } const createSlug = (nombre: string): string => {