@@ -7,6 +7,7 @@ export const useApiStore = defineStore('api', () => {
77 // --- State ---
88 const apiHost = useLocalStorage ( 'apiHost' , window . location . origin ) ;
99 const rawRoutes = ref < IGroupedRoutes [ ] > ( [ ] ) ;
10+ const fullRoutes = ref < IAPIInfo [ ] > ( [ ] ) ;
1011 const selectedRouteId = ref < string | null > ( null ) ;
1112 const selectedRouteDetails = ref < IAPIInfo | null > ( null ) ;
1213 const isLoadingRoutes = ref < boolean > ( false ) ;
@@ -82,9 +83,26 @@ export const useApiStore = defineStore('api', () => {
8283 async function fetchRoutes ( ) {
8384 isLoadingRoutes . value = true ;
8485 try {
85- const response = await fetch ( `${ apiHost . value } /docs-api/routes` ) ;
86+ const url = import . meta. env . VITE_IS_DEMO ? '/sample.json' : `${ apiHost . value } /docs-api/routes` ;
87+ const response = await fetch ( url ) ;
8688 if ( ! response . ok ) throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
87- rawRoutes . value = await response . json ( ) ;
89+ const data = await response . json ( ) ;
90+ if ( import . meta. env . VITE_IS_DEMO ) {
91+ fullRoutes . value = data ;
92+ // Group by controller for demo
93+ const grouped : { [ key : string ] : IAPIInfo [ ] } = { } ;
94+ data . forEach ( ( route : IAPIInfo ) => {
95+ const group = route . controller || 'Others' ;
96+ if ( ! grouped [ group ] ) grouped [ group ] = [ ] ;
97+ grouped [ group ] . push ( route ) ;
98+ } ) ;
99+ rawRoutes . value = Object . keys ( grouped ) . map ( group => ( {
100+ group,
101+ routes : grouped [ group ] . map ( r => ( { id : r . uri , uri : r . uri , methods : [ r . http_method ] } ) )
102+ } ) ) ;
103+ } else {
104+ rawRoutes . value = data ;
105+ }
88106 } catch ( err : any ) {
89107 requestError . value = `Failed to fetch routes: ${ err . message } . Check API Host setting.` ;
90108 console . error ( requestError . value ) ;
@@ -99,9 +117,13 @@ export const useApiStore = defineStore('api', () => {
99117 // Clear previous response
100118 clearResponse ( ) ;
101119 try {
102- const response = await fetch ( `${ apiHost . value } /docs-api/routes/${ id } ` ) ;
103- if ( ! response . ok ) throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
104- selectedRouteDetails . value = await response . json ( ) ;
120+ if ( import . meta. env . VITE_IS_DEMO ) {
121+ selectedRouteDetails . value = fullRoutes . value . find ( r => r . uri === id ) || null ;
122+ } else {
123+ const response = await fetch ( `${ apiHost . value } /docs-api/routes/${ id } ` ) ;
124+ if ( ! response . ok ) throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
125+ selectedRouteDetails . value = await response . json ( ) ;
126+ }
105127 } catch ( err : any ) {
106128 requestError . value = `Failed to fetch route details for ${ id } : ${ err . message } ` ;
107129 console . error ( requestError . value ) ;
0 commit comments