fix(chatbot-taff): lecture JSON via $fetch(origin) — fonctionne dev + prod
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user