11import { cloneDeep } from 'es-toolkit/object' ;
2- import { type NextPageContext } from 'next' ;
2+ import { type GetServerSidePropsContext } from 'next' ;
33
44import HomeScene from '~/scenes/HomeScene' ;
55import { type HomePageProps } from '~/types/pages' ;
@@ -12,13 +12,14 @@ function Index(props: HomePageProps) {
1212
1313const LIMIT = 8 ;
1414
15- Index . getInitialProps = async ( ctx : NextPageContext ) => {
16- if ( ctx . res && ctx . query && Object . keys ( ctx . query ) . length > 0 ) {
17- ctx . res . writeHead ( 302 , {
18- Location : urlWithQuery ( '/packages' , ctx . query ) ,
19- } ) ;
20- ctx . res . end ( ) ;
21- return ;
15+ export async function getServerSideProps ( ctx : GetServerSidePropsContext ) {
16+ if ( Object . keys ( ctx . query ) . length > 0 ) {
17+ return {
18+ redirect : {
19+ destination : urlWithQuery ( '/packages' , ctx . query ) ,
20+ permanent : false ,
21+ } ,
22+ } ;
2223 }
2324
2425 const mostDownloadedResponse = await ssrFetch (
@@ -56,12 +57,14 @@ Index.getInitialProps = async (ctx: NextPageContext) => {
5657 const statisticResponse = await ssrFetch ( '/libraries/statistic' , { } , ctx ) ;
5758
5859 return {
59- mostDownloaded : await mostDownloadedResponse . json ( ) ,
60- recentlyAdded : await recentlyAddedResponse . json ( ) ,
61- recentlyUpdated : await recentlyUpdatedResponse . json ( ) ,
62- popular : await popularResponse . json ( ) ,
63- statistic : await statisticResponse . json ( ) ,
60+ props : {
61+ mostDownloaded : await mostDownloadedResponse . json ( ) ,
62+ recentlyAdded : await recentlyAddedResponse . json ( ) ,
63+ recentlyUpdated : await recentlyUpdatedResponse . json ( ) ,
64+ popular : await popularResponse . json ( ) ,
65+ statistic : await statisticResponse . json ( ) ,
66+ } ,
6467 } ;
65- } ;
68+ }
6669
6770export default Index ;
0 commit comments