@@ -17,7 +17,12 @@ interface AuthService {
1717
1818/**
1919 * Registers ObjectStack routes as a Fastify plugin.
20- * Provides Auth, GraphQL, Metadata, Data, and Storage routes.
20+ *
21+ * Only routes that need framework-specific handling (auth service, storage
22+ * file upload, GraphQL raw result, discovery wrapper) are registered explicitly.
23+ * All other routes are handled by a catch-all that delegates to
24+ * `HttpDispatcher.dispatch()`, making the adapter automatically support
25+ * new routes added to the dispatcher.
2126 *
2227 * @example
2328 * ```ts
@@ -68,6 +73,8 @@ export async function objectStackPlugin(fastify: FastifyInstance, options: Fasti
6873 } ) ;
6974 } ;
7075
76+ // ─── Explicit routes (framework-specific handling required) ────────────────
77+
7178 // --- Discovery ---
7279 fastify . get ( `${ prefix } ` , async ( _request : FastifyRequest , reply : FastifyReply ) => {
7380 return reply . send ( { data : await dispatcher . getDiscoveryInfo ( prefix ) } ) ;
@@ -78,7 +85,7 @@ export async function objectStackPlugin(fastify: FastifyInstance, options: Fasti
7885 return reply . redirect ( prefix ) ;
7986 } ) ;
8087
81- // --- Auth ---
88+ // --- Auth (needs auth service integration) ---
8289 fastify . all ( `${ prefix } /auth/*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
8390 try {
8491 const path = request . url . substring ( `${ prefix } /auth/` . length ) . split ( '?' ) [ 0 ] ;
@@ -132,7 +139,7 @@ export async function objectStackPlugin(fastify: FastifyInstance, options: Fasti
132139 }
133140 } ) ;
134141
135- // --- GraphQL ---
142+ // --- GraphQL (returns raw result, not HttpDispatcherResult) ---
136143 fastify . post ( `${ prefix } /graphql` , async ( request : FastifyRequest , reply : FastifyReply ) => {
137144 try {
138145 const result = await dispatcher . handleGraphQL ( request . body as any , { request : request . raw } ) ;
@@ -142,53 +149,30 @@ export async function objectStackPlugin(fastify: FastifyInstance, options: Fasti
142149 }
143150 } ) ;
144151
145- // --- Metadata ---
146- fastify . all ( `${ prefix } /meta/*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
147- try {
148- const urlPath = request . url . split ( '?' ) [ 0 ] ;
149- const subPath = urlPath . substring ( `${ prefix } /meta` . length ) ;
150- const method = request . method ;
151- const body = ( method === 'PUT' || method === 'POST' ) ? request . body : undefined ;
152- const result = await dispatcher . handleMetadata ( subPath , { request : request . raw } , method , body ) ;
153- return sendResult ( result , reply ) ;
154- } catch ( err : any ) {
155- return errorResponse ( err , reply ) ;
156- }
157- } ) ;
158-
159- fastify . all ( `${ prefix } /meta` , async ( request : FastifyRequest , reply : FastifyReply ) => {
160- try {
161- const method = request . method ;
162- const body = ( method === 'PUT' || method === 'POST' ) ? request . body : undefined ;
163- const result = await dispatcher . handleMetadata ( '' , { request : request . raw } , method , body ) ;
164- return sendResult ( result , reply ) ;
165- } catch ( err : any ) {
166- return errorResponse ( err , reply ) ;
167- }
168- } ) ;
169-
170- // --- Data ---
171- fastify . all ( `${ prefix } /data/*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
152+ // --- Storage (needs file upload handling) ---
153+ fastify . all ( `${ prefix } /storage/*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
172154 try {
173155 const urlPath = request . url . split ( '?' ) [ 0 ] ;
174- const subPath = urlPath . substring ( `${ prefix } /data ` . length ) ;
156+ const subPath = urlPath . substring ( `${ prefix } /storage ` . length ) ;
175157 const method = request . method ;
176- const body = ( method === 'POST' || method === 'PATCH' ) ? request . body : { } ;
177- const result = await dispatcher . handleData ( subPath , method , body , request . query , { request : request . raw } ) ;
158+ const file = ( request as any ) . file || ( request . body as any ) ?. file ;
159+ const result = await dispatcher . handleStorage ( subPath , method , file , { request : request . raw } ) ;
178160 return sendResult ( result , reply ) ;
179161 } catch ( err : any ) {
180162 return errorResponse ( err , reply ) ;
181163 }
182164 } ) ;
183165
184- // --- Storage ---
185- fastify . all ( `${ prefix } /storage/*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
166+ // ─── Catch-all: delegate to dispatcher.dispatch() ─────────────────────────
167+ // Handles meta, data, packages, analytics, automation, i18n, ui, openapi,
168+ // custom API endpoints, and any future routes added to HttpDispatcher.
169+ fastify . all ( `${ prefix } /*` , async ( request : FastifyRequest , reply : FastifyReply ) => {
186170 try {
187171 const urlPath = request . url . split ( '?' ) [ 0 ] ;
188- const subPath = urlPath . substring ( ` ${ prefix } /storage` . length ) ;
172+ const subPath = urlPath . substring ( prefix . length ) ;
189173 const method = request . method ;
190- const file = ( request as any ) . file || ( request . body as any ) ?. file ;
191- const result = await dispatcher . handleStorage ( subPath , method , file , { request : request . raw } ) ;
174+ const body = ( method === 'POST' || method === 'PUT' || method === 'PATCH' ) ? request . body : undefined ;
175+ const result = await dispatcher . dispatch ( method , subPath , body , request . query , { request : request . raw } ) ;
192176 return sendResult ( result , reply ) ;
193177 } catch ( err : any ) {
194178 return errorResponse ( err , reply ) ;
0 commit comments