1+ import { compileRouter } from "rou3/compiler" ;
12import * as _h3src from "../../src/index.ts" ;
23import * as _h3v1 from "h3-v1" ;
34import * as _h3nightly from "h3-nightly" ;
@@ -8,6 +9,7 @@ type AppFetch = (req: Request) => Response | Promise<Response>;
89export function createInstances ( ) : Array < [ string , AppFetch ] > {
910 return [
1011 [ "h3" , h3 ( _h3src ) ] ,
12+ [ "h3-compiled" , h3 ( _h3src , true ) ] ,
1113 [ "h3-nightly" , h3 ( _h3nightly as any ) ] ,
1214 [ "h3-middleware" , h3Middleware ( _h3src ) ] ,
1315 // ["h3-v1", h3v1()],
@@ -16,7 +18,7 @@ export function createInstances(): Array<[string, AppFetch]> {
1618 ] as const ;
1719}
1820
19- export function h3 ( lib : typeof _h3src ) : AppFetch {
21+ export function h3 ( lib : typeof _h3src , compiled ?: boolean ) : AppFetch {
2022 const app = new lib . H3 ( )
2123 . get ( "/" , ( ) => "Hi" )
2224 . get ( "/id/:id" , ( event ) => {
@@ -25,6 +27,10 @@ export function h3(lib: typeof _h3src): AppFetch {
2527 return `${ event . context . params ! . id } ${ name } ` ;
2628 } )
2729 . post ( "/json" , ( event ) => event . req . json ( ) ) ;
30+ if ( compiled ) {
31+ const findRoute = compileRouter ( app . _rou3 ) ;
32+ app . _findRoute = ( event ) => findRoute ( event . req . method , event . url . pathname ) ;
33+ }
2834 return app . fetch ;
2935}
3036
0 commit comments