@@ -340,18 +340,18 @@ export const composeHandler = ({
340340 trace : Sucrose . TraceInference
341341 }
342342} ) : ComposedHandler => {
343+ const isHandleFn = typeof handler === 'function'
344+ if ( ! isHandleFn ) handler = mapCompactResponse ( handler )
345+
343346 const hasErrorHandler =
344- app . config . forceErrorEncapsulation ||
347+ ( app . config . forceErrorEncapsulation && isHandleFn ) ||
345348 hooks . error . length > 0 ||
346349 app . event . error . length > 0 ||
347350 typeof Bun === 'undefined' ||
348- app . onResponse . length > 0 ||
351+ hooks . onResponse . length > 0 ||
349352 hooks . onResponse . length > 0 ||
350353 ! ! hooks . trace . length
351354
352- const isHandleFn = typeof handler === 'function'
353- if ( ! isHandleFn ) handler = mapCompactResponse ( handler )
354-
355355 const handle = isHandleFn ? `handler(c)` : `handler`
356356 const handleResponse = hooks . onResponse . length
357357 ? `\n;(async () => {${ hooks . onResponse
@@ -1440,6 +1440,16 @@ export const composeGeneralHandler = (
14401440
14411441 const maybeAsync = app . event . request . some ( isAsync )
14421442
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+
14431453 fnLiteral += `const {
14441454 app,
14451455 mapEarlyResponse,
@@ -1544,18 +1554,11 @@ export const composeGeneralHandler = (
15441554
15451555 endReport ( )
15461556
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`
15521559 } 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++' : '' }
15591562 const ctx = {
15601563 request,
15611564 store,
@@ -1737,8 +1740,7 @@ export const composeErrorHandler = (
17371740
17381741export const jitRoute = (
17391742 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)
17431745
17441746return st${ index } (ctx)`
0 commit comments