@@ -340,18 +340,18 @@ export const composeHandler = ({
340
340
trace : Sucrose . TraceInference
341
341
}
342
342
} ) : ComposedHandler => {
343
+ const isHandleFn = typeof handler === 'function'
344
+ if ( ! isHandleFn ) handler = mapCompactResponse ( handler )
345
+
343
346
const hasErrorHandler =
344
- app . config . forceErrorEncapsulation ||
347
+ ( app . config . forceErrorEncapsulation && isHandleFn ) ||
345
348
hooks . error . length > 0 ||
346
349
app . event . error . length > 0 ||
347
350
typeof Bun === 'undefined' ||
348
- app . onResponse . length > 0 ||
351
+ hooks . onResponse . length > 0 ||
349
352
hooks . onResponse . length > 0 ||
350
353
! ! hooks . trace . length
351
354
352
- const isHandleFn = typeof handler === 'function'
353
- if ( ! isHandleFn ) handler = mapCompactResponse ( handler )
354
-
355
355
const handle = isHandleFn ? `handler(c)` : `handler`
356
356
const handleResponse = hooks . onResponse . length
357
357
? `\n;(async () => {${ hooks . onResponse
@@ -1440,6 +1440,16 @@ export const composeGeneralHandler = (
1440
1440
1441
1441
const maybeAsync = app . event . request . some ( isAsync )
1442
1442
1443
+ const init = `\n
1444
+ const url = request.url
1445
+ const s = url.indexOf('/', 11)
1446
+ const qi = url.indexOf('?', s + 1)
1447
+ let path
1448
+ if(qi === -1)
1449
+ path = url.substring(s)
1450
+ else
1451
+ path = url.substring(s, qi)\n`
1452
+
1443
1453
fnLiteral += `const {
1444
1454
app,
1445
1455
mapEarlyResponse,
@@ -1544,18 +1554,11 @@ export const composeGeneralHandler = (
1544
1554
1545
1555
endReport ( )
1546
1556
1547
- fnLiteral += `
1548
- const url = request.url
1549
- const s = url.indexOf('/', 11)
1550
- const qi = ctx.qi = url.indexOf('?', s + 1)
1551
- const path = ctx.path = url.substring(s, qi === -1 ? undefined : qi)`
1557
+ fnLiteral += init
1558
+ fnLiteral += `\nctx.qi = qi\n ctx.path = path\n`
1552
1559
} else {
1553
- fnLiteral += `
1554
- const url = request.url
1555
- const s = url.indexOf('/', 11)
1556
- const qi = url.indexOf('?', s + 1)
1557
- const path = url.substring(s, qi === -1 ? undefined : qi)
1558
- ${ hasTrace ? 'const id = +requestId.value++' : '' }
1560
+ fnLiteral += init
1561
+ fnLiteral += `${ hasTrace ? 'const id = +requestId.value++' : '' }
1559
1562
const ctx = {
1560
1563
request,
1561
1564
store,
@@ -1737,8 +1740,7 @@ export const composeErrorHandler = (
1737
1740
1738
1741
export const jitRoute = (
1739
1742
index : number
1740
- ) => `if(stc${ index } ) return stc${ index } (ctx)\n
1741
-
1742
- if(st${ index } .compose) return (st${ index } = st${ index } ?.compose())(ctx)
1743
+ ) => `if(stc${ index } ) return stc${ index } (ctx)
1744
+ if(st${ index } .compose) return (stc${ index } = st${ index } .compose())(ctx)
1743
1745
1744
1746
return st${ index } (ctx)`
0 commit comments