Issues with Async Failure
Alastair Rosewood
StackBlitz
Node.js (forked) - StackBlitz
Starter project for Node.js, a JavaScript runtime built on Chrome's V8 JavaScript engine.
14 Replies
@Isaac McFadyen | YYZ01, just checked, and aparently the script fails on https://stackblitz.com/edit/node-t4hhov?file=src%2Fapi%2Fproviders%2FNWS%2Findex.ts, on lines 9-13, when it is just running a fetch request...
Fumbling for straws here, but it might be that
hono
registers routes outside of the scope of a fetch
request, which makes it fail?Huh... yeah, that might be right?
I've never used Hono TBH.
I use Polka (Lukeed's package).
GitHub
GitHub - lukeed/polka: A micro web server so fast, it'll make you d...
A micro web server so fast, it'll make you dance! :dancers: - GitHub - lukeed/polka: A micro web server so fast, it'll make you dance!
Does it support Workers? I've seen it floating around, but I don't think I have ever actually seen someone use it in Workers...
Oh wait, you're correct the only other thing I can recommend then is
itty-router
but the API is different.Yeah, the big issue for me is the fact that
itty
doesn't really support middleware for stuff like CORS etc. Might have to use it though...Hmm... yeah it does?
If you do a
.any("*", () => {...add cors here})
then don't return in the handler I think?I was looking at it, and it looks like middleware must manually be applied to each route.
Let me check...
Oh, annoying.
So, looks like you can run middleware, but only ahead of the final route, which means that I could modify incoming data, but not the outgoing headers...
So works, but it cannot modify the final response headers.
Oh, interesting.
Because
itty-router
is so simple, the second it detects that a response is returned, it stops processing middleware, and just returns the response directly, before its headers can be modified. This is why frameworks like hono
and express
(I believe) support the next()
function, that allows you to use a middleware before a route, intercept the response from the route, and then modify it before it is returned.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Oh sweet! Didn't know this, thanks!