Skip to content

Commit 335aef0

Browse files
authored
Merge pull request #961 from macabeus/fix-issue-959
🔧 fix literal handler when AOT is off
2 parents 287dd53 + 3fe4772 commit 335aef0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/dynamic-handle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { TransformDecodeError } from '@sinclair/typebox/value'
2020

2121
// JIT Handler
2222
export type DynamicHandler = {
23-
handle: Handler<any, any>
23+
handle: unknown | Handler<any, any>
2424
content?: string
2525
hooks: LifeCycleStore
2626
validator?: SchemaValidator
@@ -331,7 +331,7 @@ export const createDynamicHandler =
331331
}
332332
}
333333

334-
let response = handle(context)
334+
let response = typeof handle === 'function' ? handle(context) : handle
335335
if (response instanceof Promise) response = await response
336336

337337
if (!hooks.afterHandle.length) {

test/core/dynamic.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ describe('Dynamic Mode', () => {
1313
expect(res).toBe('Hi')
1414
})
1515

16+
it('handle literal', async () => {
17+
const app = new Elysia({ aot: false }).get('/', 'Hi');
18+
19+
const response = await app.handle(req('/')).then((x) => x.text());
20+
21+
expect(response).toBe('Hi');
22+
})
23+
1624
it('handle body', async () => {
1725
const app = new Elysia({
1826
aot: false

0 commit comments

Comments
 (0)