Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Bruno Predot
/
tmdb_test
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Bruno Predot
2025-05-18 12:50:46 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
93c94947a9314b3051e34565410fd4e0c9057fb0
93c94947
1 parent
344a6427
Finalisation du plugin oFetch.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
plugins/oFetch.ts
plugins/oFetch.ts
View file @
93c9494
...
...
@@ -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 */
}
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"
,
"..."
);
// 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.
...
...
Please
register
or
login
to post a comment