This commit is contained in:
2026-02-16 07:59:52 +01:00
parent 1fc267faa8
commit b8b8e53f07
70 changed files with 3088 additions and 272 deletions

33
app/utils/strapi.js Normal file
View File

@@ -0,0 +1,33 @@
// app/utils/strapi.js
export function getStrapiBaseUrl(event) {
// En server/Nitro, on récupère runtimeConfig via l'event si dispo,
// sinon on retombe sur la variable d'env publique.
const base =
event?.context?.runtimeConfig?.public?.strapiUrl ||
process.env.NUXT_PUBLIC_STRAPI_URL
if (!base) {
throw new Error("Missing runtimeConfig.public.strapiUrl (NUXT_PUBLIC_STRAPI_URL)")
}
try {
new URL(base)
} catch {
throw new Error(`Invalid Strapi base URL: ${base}`)
}
return base.replace(/\/$/, "")
}
export async function strapiFetch(event, path, options = {}) {
const base = getStrapiBaseUrl(event)
const url = `${base}${path.startsWith("/") ? path : `/${path}`}`
return await $fetch(url, {
...options,
headers: {
...(options.headers || {}),
},
})
}