Bruno Predot

Finalisation du plugin oFetch.

... ... @@ -12,16 +12,20 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
const runtimeConfig: RuntimeConfig = useRuntimeConfig();
// On rend la configuration que l'on crée globale grâce à 'globalThis.$fetch'.
globalThis.$fetch = ofetch.create({
// Base url example : https://nom-de-domaine/api.
baseURL: runtimeConfig.public.apiTMDBUrl,
/**
* Request interceptor.
*/
onRequest({ request, options }) {
if (request) { /** empty */ }
// Set the request headers
// note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile
options.headers.set("Authorization", "...");
if (typeof request === "string" && request.includes("movie")) {
/** empty */
// Set the baseURL to the TMDB API URL.
// Base url example : https://nom-de-domaine/something.
options.baseURL = runtimeConfig.public.apiTMDBUrl;
// Set the request headers
// note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile.
options.headers.set("Authorization", `Bearer ${runtimeConfig.public.apiTMDBBearer}`);
}
},
/**
* Request error interceptor.
... ...