21 lines
715 B
TypeScript
21 lines
715 B
TypeScript
import { readFileSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
import type { Pratique } from '~/types/pratique'
|
|
|
|
/**
|
|
* GET /api/pratiques
|
|
* Lit public/data/pratiques-regeneratives.json
|
|
* Retourne { list: Pratique[], source: 'static' }
|
|
*/
|
|
export default defineEventHandler(async (_event) => {
|
|
try {
|
|
const jsonPath = resolve(process.cwd(), 'public/data/pratiques-regeneratives.json')
|
|
const raw = readFileSync(jsonPath, 'utf-8')
|
|
const list: Pratique[] = JSON.parse(raw)
|
|
return { list, source: 'static' }
|
|
} catch (err) {
|
|
console.error('[PRATIQUES API] Erreur lecture JSON:', err)
|
|
throw createError({ statusCode: 503, message: 'Données pratiques-regeneratives indisponibles' })
|
|
}
|
|
})
|