Showing
1 changed file
with
9 additions
and
5 deletions
@@ -12,16 +12,20 @@ export default defineNuxtPlugin(async (_nuxtApp) => { | @@ -12,16 +12,20 @@ export default defineNuxtPlugin(async (_nuxtApp) => { | ||
12 | const runtimeConfig: RuntimeConfig = useRuntimeConfig(); | 12 | const runtimeConfig: RuntimeConfig = useRuntimeConfig(); |
13 | // On rend la configuration que l'on crée globale grâce à 'globalThis.$fetch'. | 13 | // On rend la configuration que l'on crée globale grâce à 'globalThis.$fetch'. |
14 | globalThis.$fetch = ofetch.create({ | 14 | globalThis.$fetch = ofetch.create({ |
15 | - // Base url example : https://nom-de-domaine/api. | ||
16 | - baseURL: runtimeConfig.public.apiTMDBUrl, | ||
17 | /** | 15 | /** |
18 | * Request interceptor. | 16 | * Request interceptor. |
19 | */ | 17 | */ |
20 | onRequest({ request, options }) { | 18 | onRequest({ request, options }) { |
21 | - if (request) { /** empty */ } | 19 | + if (typeof request === "string" && request.includes("movie")) { |
20 | + /** empty */ | ||
21 | + // Set the baseURL to the TMDB API URL. | ||
22 | + // Base url example : https://nom-de-domaine/something. | ||
23 | + options.baseURL = runtimeConfig.public.apiTMDBUrl; | ||
24 | + | ||
22 | // Set the request headers | 25 | // Set the request headers |
23 | - // note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile | 26 | + // note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile. |
24 | - options.headers.set("Authorization", "..."); | 27 | + options.headers.set("Authorization", `Bearer ${runtimeConfig.public.apiTMDBBearer}`); |
28 | + } | ||
25 | }, | 29 | }, |
26 | /** | 30 | /** |
27 | * Request error interceptor. | 31 | * Request error interceptor. |
-
Please register or login to post a comment