This repository was archived by the owner on Jun 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
web/src/app/api/[homepage] Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
- import { HomePageContent } from "@/types/strapi" ;
1
+ import { getNews } from "@/helpers/homepage" ;
2
+ import { SingleType } from "@/types/strapi" ;
2
3
3
4
export async function GET ( ) {
4
5
const res = await fetch ( `${ process . env . CMS_API } /home?populate=deep` , {
@@ -7,10 +8,25 @@ export async function GET() {
7
8
"API-Key" : process . env . CMS_API_TOKEN ! ,
8
9
} ,
9
10
} ) ;
11
+
10
12
if ( ! res . ok ) {
11
13
throw new Error ( "Fetching single type component home failed" ) ;
12
14
}
13
15
14
- const content = ( await res . json ( ) ) as HomePageContent ;
15
- return Response . json ( content . data . attributes ) ;
16
+ const homePageData = ( await res . json ( ) ) as SingleType ;
17
+
18
+ const news = homePageData . data . attributes . body
19
+ . map ( ( el , i ) => {
20
+ if ( "newsCount" in el ) return { index : i , newsCount : el . newsCount } ;
21
+ } )
22
+ . filter ( Boolean ) ;
23
+
24
+ for ( const newsEntry of news ) {
25
+ if ( ! newsEntry ) break ;
26
+ const fetchedNews = await getNews ( newsEntry ?. newsCount ) ;
27
+
28
+ homePageData . data . attributes . body [ newsEntry . index ] = fetchedNews ;
29
+ }
30
+
31
+ return Response . json ( homePageData . data . attributes ) ;
16
32
}
You can’t perform that action at this time.
0 commit comments