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.
|
* 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'
|
import { checkRateLimitJson } from '~/server/utils/rateLimitJson'
|
||||||
|
|
||||||
interface PlateformeMinimal {
|
interface PlateformeMinimal {
|
||||||
@@ -67,12 +65,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
throw createError({ statusCode: 400, statusMessage: 'Question trop courte.' })
|
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[] = []
|
let plateformes: PlateformeMinimal[] = []
|
||||||
try {
|
try {
|
||||||
const jsonUrl = new URL('../../public/data/plateformes-taff.json', import.meta.url)
|
const origin = getRequestURL(event).origin
|
||||||
const raw = JSON.parse(readFileSync(fileURLToPath(jsonUrl), 'utf8'))
|
const json = await $fetch<{ plateformes: PlateformeMinimal[] }>('/data/plateformes-taff.json', {
|
||||||
plateformes = (raw.plateformes ?? []).map((p: any) => ({
|
baseURL: origin,
|
||||||
|
})
|
||||||
|
plateformes = (json.plateformes ?? []).map((p: any) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
nom: p.nom,
|
nom: p.nom,
|
||||||
type: p.type,
|
type: p.type,
|
||||||
|
|||||||
Reference in New Issue
Block a user