@@ -41,14 +41,17 @@ export const nodeRequestToWebstand = (
4141 abortController ?: AbortController
4242) => {
4343 let _signal : AbortSignal
44+ let _body : unknown
4445
4546 return new Request ( getUrl ( req ) , {
4647 method : req . method ,
4748 headers : req . headers as Record < string , string > ,
4849 get body ( ) {
4950 if ( req . method === 'GET' || req . method === 'HEAD' ) return null
51+ if ( _body !== undefined ) return _body
52+ if ( req . readable ) return ( _body = Readable . toWeb ( req ) as any )
5053
51- return Readable . toWeb ( req ) as any
54+ return null
5255 } ,
5356 get signal ( ) {
5457 if ( _signal ) return _signal
@@ -76,16 +79,20 @@ export const node = () => {
7679 mapCompactResponse
7780 } ,
7881 composeHandler : {
79- // declare(inference) {
80- // if (inference.request)
81- // return (
82- // `Object.defineProperty(c,'request',{` +
83- // `get(){` +
84- // `return nodeRequestToWebstand(c[ElysiaNodeContext].req)` +
85- // `}` +
86- // `})\n`
87- // )
88- // },
82+ declare ( inference ) {
83+ if ( inference . request || inference . request )
84+ return (
85+ `if(!('request' in c)){` +
86+ `let _request\n` +
87+ `Object.defineProperty(c,'request',{` +
88+ `get(){` +
89+ `if(_request)return _request\n` +
90+ `return _request=nodeRequestToWebstand(c[ElysiaNodeContext].req)` +
91+ `}` +
92+ `})` +
93+ '}\n'
94+ )
95+ } ,
8996 mapResponseContext : 'c[ElysiaNodeContext].res' ,
9097 headers : `c.headers=c[ElysiaNodeContext].req.headers\n` ,
9198 inject : {
@@ -208,12 +215,12 @@ export const node = () => {
208215 fnLiteral += `let _request\n` + `const c={`
209216
210217 // @ts -ignore protected
211- if ( app . inference . request || app . inference . cookie )
212- fnLiteral +=
213- `get request(){` +
214- `if(_request)return _request\n` +
215- `return _request = nodeRequestToWebstand(r)` +
216- `},`
218+ // if (app.inference.request || app.inference.cookie)
219+ // fnLiteral +=
220+ // `get request(){` +
221+ // `if(_request)return _request\n` +
222+ // `return _request = nodeRequestToWebstand(r)` +
223+ // `},`
217224
218225 fnLiteral +=
219226 `store,` +
@@ -348,10 +355,10 @@ export const node = () => {
348355 typeof options === 'number'
349356 ? options
350357 : {
351- ...options ,
352- // @ts -ignore
353- host : options ?. hostname
354- } ,
358+ ...options ,
359+ // @ts -ignore
360+ host : options ?. hostname
361+ } ,
355362 ( ) => {
356363 const address = server . address ( )
357364 const hostname =
@@ -408,10 +415,10 @@ export const node = () => {
408415 typeof options === 'number'
409416 ? options
410417 : {
411- ...options ,
412- // @ts -ignore
413- host : options ?. hostname
414- }
418+ ...options ,
419+ // @ts -ignore
420+ host : options ?. hostname
421+ }
415422 )
416423 } ,
417424 requestIP ( ) {
@@ -447,10 +454,10 @@ export const node = () => {
447454 typeof options === 'object'
448455 ? ( options as any )
449456 : {
450- port : options
451- }
457+ port : options
458+ }
452459 )
453- } catch { }
460+ } catch { }
454461 } )
455462 }
456463 )
0 commit comments