@@ -13,11 +13,16 @@ export class StrapiError extends Error {
1313 }
1414}
1515
16- const createClient = ( config ?: Omit < Config , 'baseURL' > ) =>
17- strapi ( {
16+ const createClient = ( config ?: Omit < Config , 'baseURL' > , isDraftMode : boolean = false ) => {
17+ return strapi ( {
1818 baseURL : `${ process . env . NEXT_PUBLIC_API_URL ?? '' } /api` ,
19+ headers : {
20+ "strapi-encode-source-maps" : isDraftMode ? "true" : "false" ,
21+ ...config ?. headers ,
22+ } ,
1923 ...config ,
2024 } ) ;
25+ }
2126
2227/**
2328 * Fetches a collection type from Strapi.
@@ -32,7 +37,7 @@ export async function fetchCollectionType<T = API.Document[]>(
3237 const { isEnabled : isDraftMode } = await draftMode ( ) ;
3338
3439 try {
35- const { data } = await createClient ( config )
40+ const { data } = await createClient ( config , isDraftMode )
3641 . collection ( collectionName )
3742 . find ( {
3843 ...options ,
@@ -62,7 +67,7 @@ export async function fetchSingleType<T = API.Document>(
6267 const { isEnabled : isDraftMode } = await draftMode ( ) ;
6368
6469 try {
65- const { data } = await createClient ( config )
70+ const { data } = await createClient ( config , isDraftMode )
6671 . single ( singleTypeName )
6772 . find ( {
6873 ...options ,
@@ -93,7 +98,7 @@ export async function fetchDocument<T = API.Document>(
9398 const { isEnabled : isDraftMode } = await draftMode ( ) ;
9499
95100 try {
96- const { data } = await createClient ( config )
101+ const { data } = await createClient ( config , isDraftMode )
97102 . collection ( collectionName )
98103 . findOne ( documentId , {
99104 ...options ,
0 commit comments