Open otherguy opened 11 months ago
@SaltyAom any progress on this one?
If I understand correctly, you want to get both request, and response on onAfterResponse
(previously 'onResponse').
onAfterResponse
include response
by default since name change or since 1.1.
new Elysia()
.derive(({ server, request }) => {
return {
ip: String(server?.requestIP(request))
}
})
.onError((ctx) => {
ctx.store = { error: ctx.error, ...ctx.store }
})
.onRequest((ctx) => {
ctx.store = { requestStart: process.hrtime.bigint(), ...ctx.store }
})
.onAfterResponse(({ request, response }) => {
console.log({
request,
response
})
})
.get('/', () => 'a')
.listen(3000)
Creating a new issue since #190 was closed.
Unfortunately, the
onResponse
handler can neither access the actualResponse
object (to get e.g. response length) nor does it have access to the underlying socket, to get the request protocol for example.Would it be possible to get the
Response
object inside the context of theonResponse
handler? And an access toreq.socket
in the TypeScriptRequest
object?Responding to
Using
elysia@0.7.29
, in a minimal example, when used as a middleware,response
isundefined
.What I would want is to get the response object (to get the response size) in either
onAfterHandle
or, preferably,onResponse
.Similarly, in
onResponse
, it would be great to have access toctx.request.socket
to get the original request protocol.