Skip to content

Commit 35ae4b6

Browse files
committed
🎉 feat: release 1.2.17
1 parent 0ece686 commit 35ae4b6

File tree

5 files changed

+67
-51
lines changed

5 files changed

+67
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.2.17 - 21 Feb 2025
2+
Bug fix:
3+
- `.mount` doesn't return pass entire request
4+
15
# 1.2.16 - 21 Feb 2025
26
Improvement:
37
- `AfterHandler` infer response type

example/a.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { TypeCompiler } from '@sinclair/typebox/compiler'
21
import { Elysia, t } from '../src'
3-
import { req } from '../test/utils'
42

5-
const app = new Elysia({
6-
experimental: {
7-
encodeSchema: true
8-
}
9-
}).get('/', () => 'hello world', {
10-
response: t
11-
.Transform(t.String())
12-
.Decode((v) => v)
13-
.Encode(() => 'encoded')
3+
const app = new Elysia().mount(async (request) => {
4+
// const body = await request.json()
5+
// console.log({ body })
6+
return new Response("OK")
147
})
158

16-
app.handle(req('/'))
17-
.then((x) => x.json())
9+
app.handle(
10+
new Request('http://localhost', {
11+
method: 'GET',
12+
// headers: {
13+
// 'Content-Type': 'application/json'
14+
// },
15+
// body: JSON.stringify({ hello: 'world' })
16+
})
17+
)
18+
.then((x) => x.text())
1819
.then(console.log)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.2.16",
4+
"version": "1.2.17",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/index.ts

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,27 +4108,22 @@ export default class Elysia<
41084108
? handle.compile().fetch
41094109
: handle!
41104110

4111-
const handler: Handler<any, any> = async ({ request, path }) => {
4112-
if (
4113-
request.method === 'GET' ||
4114-
request.method === 'HEAD' ||
4115-
!request.headers.get('content-type')
4116-
)
4117-
return run(
4118-
new Request(replaceUrlPath(request.url, path || '/'), {
4119-
...request,
4120-
method: request.method
4121-
})
4122-
)
4123-
4124-
return run(
4111+
const handler: Handler = ({ request, path }) =>
4112+
run(
41254113
new Request(replaceUrlPath(request.url, path || '/'), {
4126-
...request,
41274114
method: request.method,
4128-
body: await request.arrayBuffer()
4115+
headers: request.headers,
4116+
signal: request.signal,
4117+
credentials: request.credentials,
4118+
referrerPolicy: request.referrerPolicy as any,
4119+
duplex: request.duplex,
4120+
redirect: request.redirect,
4121+
mode: request.mode,
4122+
keepalive: request.keepalive,
4123+
integrity: request.integrity,
4124+
body: request.body
41294125
})
41304126
)
4131-
}
41324127

41334128
this.all('/*', handler as any, {
41344129
parse: 'none'
@@ -4137,37 +4132,31 @@ export default class Elysia<
41374132
return this
41384133
}
41394134

4135+
if (!handle) return this
4136+
41404137
const length = path.length - (path.endsWith('*') ? 1 : 0)
41414138

41424139
if (handle instanceof Elysia) handle = handle.compile().fetch
41434140

4144-
const handler: Handler<any, any> = async ({ request, path }) => {
4145-
if (
4146-
request.method === 'GET' ||
4147-
request.method === 'HEAD' ||
4148-
!request.headers.get('content-type')
4149-
)
4150-
return (handle as Function)(
4151-
new Request(
4152-
replaceUrlPath(request.url, path.slice(length) || '/'),
4153-
{
4154-
...request,
4155-
method: request.method
4156-
}
4157-
)
4158-
)
4159-
4160-
return (handle as Function)(
4141+
const handler: Handler = ({ request, path }) =>
4142+
handle(
41614143
new Request(
41624144
replaceUrlPath(request.url, path.slice(length) || '/'),
41634145
{
4164-
...request,
41654146
method: request.method,
4166-
body: await request.arrayBuffer()
4147+
headers: request.headers,
4148+
signal: request.signal,
4149+
credentials: request.credentials,
4150+
referrerPolicy: request.referrerPolicy as any,
4151+
duplex: request.duplex,
4152+
redirect: request.redirect,
4153+
mode: request.mode,
4154+
keepalive: request.keepalive,
4155+
integrity: request.integrity,
4156+
body: request.body
41674157
}
41684158
)
41694159
)
4170-
}
41714160

41724161
this.all(
41734162
path,

test/core/mount.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,26 @@ describe('Mount', () => {
116116
path: 'http://localhost/hello'
117117
})
118118
})
119+
120+
it('preserve headers', async () => {
121+
const app = new Elysia().mount((request) => {
122+
// @ts-expect-error Bun has toJSON
123+
return Response.json(request.headers.toJSON())
124+
})
125+
126+
const response = await app
127+
.handle(
128+
new Request('http://localhost/v1/hello', {
129+
method: 'PUT',
130+
headers: {
131+
'x-test': 'test'
132+
}
133+
})
134+
)
135+
.then((x) => x.json())
136+
137+
expect(response).toEqual({
138+
'x-test': 'test'
139+
})
140+
})
119141
})

0 commit comments

Comments
 (0)