From 70b9b1aa3ccd834a24efd1e79130d99c6d582b1f Mon Sep 17 00:00:00 2001 From: Jules Neny Date: Thu, 7 May 2026 01:10:29 +0200 Subject: [PATCH] =?UTF-8?q?fix(chatbot-taff):=20lecture=20JSON=20via=20$fe?= =?UTF-8?q?tch(origin)=20=E2=80=94=20fonctionne=20dev=20+=20prod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remplace readFileSync (chemin instable Nitro) par $fetch sur le serveur lui-même qui sert déjà plateformes-taff.json en statique. Co-Authored-By: Claude Sonnet 4.6 --- server/api/chatbot-taff.post.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/api/chatbot-taff.post.ts b/server/api/chatbot-taff.post.ts index 23a0838..33efa48 100644 --- a/server/api/chatbot-taff.post.ts +++ b/server/api/chatbot-taff.post.ts @@ -4,8 +4,6 @@ * Lit plateformes-taff.json, appelle Mistral Small, retourne recommandations. */ -import { readFileSync } from 'node:fs' -import { fileURLToPath } from 'node:url' import { checkRateLimitJson } from '~/server/utils/rateLimitJson' interface PlateformeMinimal { @@ -67,12 +65,14 @@ export default defineEventHandler(async (event) => { throw createError({ statusCode: 400, statusMessage: 'Question trop courte.' }) } - // Lire le JSON statique des plateformes + // Lire le JSON statique des plateformes (servi en public par Nitro) let plateformes: PlateformeMinimal[] = [] try { - const jsonUrl = new URL('../../public/data/plateformes-taff.json', import.meta.url) - const raw = JSON.parse(readFileSync(fileURLToPath(jsonUrl), 'utf8')) - plateformes = (raw.plateformes ?? []).map((p: any) => ({ + const origin = getRequestURL(event).origin + const json = await $fetch<{ plateformes: PlateformeMinimal[] }>('/data/plateformes-taff.json', { + baseURL: origin, + }) + plateformes = (json.plateformes ?? []).map((p: any) => ({ id: p.id, nom: p.nom, type: p.type,