🔧 fix: #1667 skip body parsing on mount with dynamic mode

This commit is contained in:
saltyaom
2026-01-14 11:09:03 +07:00
parent a555850247
commit c7d7f99e98
4 changed files with 38 additions and 18 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
# 1.4.22
Bug fix:
- [#1671](https://github.com/elysiajs/elysia/issues/1671) mount() produces incorrect URL path when Elysia instance has prefix option
- [#1671](https://github.com/elysiajs/elysia/issues/1671) mount produces incorrect URL path when Elysia instance has prefix option
- [#1667](https://github.com/elysiajs/elysia/issues/1667) skip body parsing on mount with dynamic mode
- ValueError with summary missing types
- Elysia not using Bun.routes
+6 -15
View File
@@ -1,18 +1,9 @@
import { Elysia } from '../src'
const sdkApp = new Elysia({ prefix: '/sdk' }).mount(
'/problems-domain',
(request) => {
console.log(request.url)
async function mountedHandler(request: Request): Promise<Response> {
return Response.json(await request.json())
}
return Response.json({ path: new URL(request.url).pathname })
}
)
const app = new Elysia().use(sdkApp)
const response = await app
.handle(new Request('http://localhost/sdk/problems-domain/problems'))
.then((x) => x.text())
console.log(response)
const serverAotFalse = new Elysia({ aot: false })
.mount('/api', async (request) => Response.json(await request.json()))
.listen(3002)
+5
View File
@@ -114,6 +114,11 @@ export const createDynamicHandler = (app: AnyElysia) => {
const { handle, validator, content, route } = handler.store
hooks = handler.store.hooks
// @ts-ignore
if (hooks.config?.mount)
// @ts-ignore
return hooks.config.mount(request)
let body: string | Record<string, any> | undefined
if (request.method !== 'GET' && request.method !== 'HEAD') {
if (content) {
+25 -2
View File
@@ -138,7 +138,7 @@ describe('Mount', () => {
})
})
it('mount without prefix - strips mount path', async () => {
it('without prefix - strips mount path', async () => {
const app = new Elysia().mount('/sdk/problems-domain', (request) => {
return Response.json({ path: new URL(request.url).pathname })
})
@@ -152,7 +152,7 @@ describe('Mount', () => {
expect(response.path).toBe('/problems')
})
it('mount with prefix - should strip both prefix and mount path', async () => {
it('with prefix - should strip both prefix and mount path', async () => {
const sdkApp = new Elysia({ prefix: '/sdk' }).mount(
'/problems-domain',
(request) => {
@@ -170,4 +170,27 @@ describe('Mount', () => {
expect(response.path).toBe('/problems')
})
it('handle body in aot: false', async () => {
const app = new Elysia({ aot: false }).mount('/api', async (request) =>
Response.json(await request.json())
)
const response = await app
.handle(
new Request('http://localhost/api', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({ message: 'hello world' })
})
)
.then((x) => x.json())
expect(response).toEqual({
message: 'hello world'
})
})
})