Skip to content

Commit 8643e0e

Browse files
committed
🎉 feat: release
1 parent 160bf0e commit 8643e0e

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# 1.2.4 - 9 Jan 2024
2-
Bug fix:
1+
# 1.2.5 - 1 Feb 2025
2+
- [#18](https://github.com/elysiajs/node/issues/18) reading cookie cause an error
3+
- Unable to set response status when error is thrown
4+
5+
# 1.2.4 - 1 Feb 2025
6+
Change:
37
- Support Elysia 1.2.11
8+
9+
Bug fix:
410
- [#23](https://github.com/elysiajs/node/issues/23) Response body object should not be disturbed or locked
511
- [#15](https://github.com/elysiajs/node/issues/15) Possibly fix `ReadableStream` duplex issue?
612
- [#14](https://github.com/elysiajs/node/issues/14) ReadableStream has already been used if request is reference multiple time

example/c.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import { Elysia, t } from 'elysia'
22
import { node } from '../src'
33
import cors from '@elysiajs/cors'
44

5-
const app = new Elysia({
6-
adapter: node()
7-
})
8-
.use(cors())
9-
.get('/home', () => {
10-
return 'Home'
11-
})
5+
const app = new Elysia({ adapter: node() })
6+
.use((app) =>
7+
app
8+
.derive({ as: 'global' }, async ({ cookie }) => {})
9+
.onAfterHandle({ as: 'global' }, async ({ response }) => {
10+
console.log('onAfterHandle', response)
11+
// await commitSession();
12+
return response
13+
})
14+
)
15+
.get('/', () => 'Hello World')
16+
.listen(3000)
17+
18+
console.log(app._handle)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/node",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "Plugin for Elysia for retreiving Bearer token",
55
"license": "MIT",
66
"scripts": {

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export const node = () => {
208208
fnLiteral += `let _request\n` + `const c={`
209209

210210
// @ts-ignore protected
211-
if (app.inference.request)
211+
if (app.inference.request || app.inference.cookie)
212212
fnLiteral +=
213213
`get request(){` +
214214
`if(_request)return _request\n` +
@@ -293,7 +293,7 @@ export const node = () => {
293293
`res.end(error.message)\n` +
294294
`return [error.message, context.set]`,
295295
unknownError:
296-
`context.set.status=error.status\n` +
296+
`if(error.status)context.set.status=error.status\n` +
297297
`res.writeHead(context.set.status, context.set.headers)\n` +
298298
`res.end(error.message)\n` +
299299
`return [error.message, context.set]`

test/core/basic.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ describe('Node - Core', () => {
7373
adapter: node()
7474
})
7575
.use(plugin)
76-
.listen(8000, ({ port }) => {
77-
console.log(`Server is running on http://localhost:${port}`)
78-
})
76+
.compile()
7977

8078
inject(
8179
// @ts-ignore
@@ -98,4 +96,34 @@ describe('Node - Core', () => {
9896
}
9997
)
10098
})
99+
100+
it('handle cookie', () => {
101+
const app = new Elysia({ adapter: node() })
102+
.use((app) =>
103+
app
104+
.derive({ as: 'global' }, async ({ cookie }) => {})
105+
.onAfterHandle({ as: 'global' }, async ({ response }) => {
106+
return response
107+
})
108+
)
109+
.get('/', () => 'ok')
110+
.compile()
111+
112+
inject(
113+
// @ts-ignore
114+
app._handle,
115+
{
116+
path: '/',
117+
method: 'GET'
118+
},
119+
(error, res) => {
120+
expect(error).toBeNull()
121+
122+
expect(res?.body).toBe('ok')
123+
expect(res?.headers['content-type']).toBe(
124+
'text/plain;charset=utf8'
125+
)
126+
}
127+
)
128+
})
101129
})

0 commit comments

Comments
 (0)