On the server, `getRequestEvent()` sometimes returns null

This happens not that frequently, but still happens. I am calling a function from middleware. In that function, I do getRequestEvent and there I am getting it as null
1 Reply
peerreynders
peerreynders2mo ago
I am calling a function from middleware. In that function, I do getRequestEvent
Don't. You are handed a FetchEvent parameter in middleware, exclusively use that. Consequently pass that event to the function rather than using getRequestEvent inside it. Similarly with API routes you are handed an APIEvent so you use that in that processing context. getRequestEvent is just a backdoor to obtain the request inside "use server" sections. So the availability of the request via getRequestEvent is highly processing context sensitive.
SolidStart Release Candidate Documentation
SolidStart Release Candidate Documentation
Early release documentation and resources for SolidStart Release Candidate
GitHub
solid-start/packages/start/src/server/types.ts at 771aedebb55bf4347...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.