Skip to content

Commit c217fee

Browse files
committed
🔧 fix: possibly fix body duplex issue
1 parent 306234a commit c217fee

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 1.2.4 - 9 Jan 2024
22
Bug fix:
33
- Support Elysia 1.2.11
4+
- [#15](https://github.com/elysiajs/node/issues/15) Possibly fix `ReadableStream` duplex issue?
45
- [#14](https://github.com/elysiajs/node/issues/14) ReadableStream has already been used if request is reference multiple time
56

67
# 1.2.3 - 27 Dec 2024

example/c.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import { Elysia } from 'elysia'
22
import { node } from '../src'
3-
4-
const plugin = new Elysia({ prefix: '/api/v1' }).post(
5-
'/',
6-
async ({ body, store, error, request }) => {
7-
return {
8-
message: 'Hello World'
9-
}
10-
}
11-
)
3+
import cors from '@elysiajs/cors'
124

135
const app = new Elysia({
146
adapter: node()
157
})
16-
.use(plugin)
8+
.use(
9+
cors({
10+
origin: true,
11+
credentials: true,
12+
preflight: true
13+
})
14+
)
15+
.post('/', ({ body }) => body)
1716
.listen(8000, ({ port }) => {
1817
console.log(`Server is running on http://localhost:${port}`)
18+
19+
fetch('http://localhost:8000', {
20+
headers: {
21+
authorization: `Bearer 12345`
22+
}
23+
})
1924
})
2025

2126
// console.log(app._handle.toString())

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export const nodeRequestToWebstand = (
6363
return _signal
6464
},
6565
// @ts-expect-error
66-
duplex: 'content-type' in req.headers ? 'half' : undefined
66+
// ? https://github.com/nodejs/node/issues/46221#issuecomment-1426707013
67+
duplex: 'content-length' in req.headers ? true : undefined
6768
})
6869
}
6970

0 commit comments

Comments
 (0)