@@ -11,26 +11,26 @@ Bun.serve({
11
11
async fetch ( req ) {
12
12
const url = new URL ( req . url )
13
13
14
- const foundRoute : Route = routesList . find ( ( route : Route ) => {
14
+ const foundRoute : Route | undefined = routesList . find ( ( route : Route ) => {
15
15
const pattern = new RegExp ( `^${ route . uri . replace ( / : \w + / g, '\\w+' ) } $` )
16
16
17
17
return pattern . test ( url . pathname )
18
- } ) as Route
18
+ } )
19
19
20
20
if ( url . pathname === '/favicon.ico' )
21
21
return new Response ( '' )
22
22
23
23
if ( ! foundRoute )
24
24
return new Response ( 'Not found' , { status : 404 } )
25
25
26
- addRouteParamsandQuery ( url , foundRoute )
26
+ addRouteParamsAndQuery ( url , foundRoute )
27
27
executeMiddleware ( foundRoute )
28
28
29
- return execute ( foundRoute , req , { statusCode : foundRoute . statusCode } )
29
+ return execute ( foundRoute , req , { statusCode : foundRoute ? .statusCode } )
30
30
} ,
31
31
} )
32
32
33
- function addRouteParamsandQuery ( url : URL , route : Route ) : void {
33
+ function addRouteParamsAndQuery ( url : URL , route : Route ) : void {
34
34
if ( ! isObjectNotEmpty ( url . searchParams ) )
35
35
request . addQuery ( url )
36
36
@@ -56,7 +56,10 @@ function executeMiddleware(route: Route): void {
56
56
}
57
57
}
58
58
59
- function execute ( route : Route , request : any , { statusCode } : { statusCode : StatusCode } ) {
59
+ function execute ( route : Route , request : any , { statusCode } : { statusCode ?: StatusCode } ) {
60
+ if ( ! statusCode )
61
+ statusCode = 200
62
+
60
63
if ( route ?. method === 'GET' && ( statusCode === 301 || statusCode === 302 ) ) {
61
64
const callback = String ( route . callback )
62
65
0 commit comments