Cookie handling for fetch in Node.js - small CookieJar plugin for Luminara #179949
Replies: 3 comments 1 reply
-
|
curious does it handle cookies across redirects automatically (similar to browser fetch)? also how iss performance when sharing jars across multiple clients under load? I have seen tough-cookie get a bit heavy in high-throughput cases, so wondering if youβve optimized that in your implementation. either way this looks like a clean solution to a long-standing Node fetch pain point |
Beta Was this translation helpful? Give feedback.
-
|
Great question! This is a very practical solution for Node.js cookie handling. A few additional thoughts that might help others:
Your Luminara plugin looks like an excellent abstraction for Luminara-specific needs. The implementation details you shared (automatic Set-Cookie capture, redirect handling) are exactly what teams need for production systems. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for sharing this. Cookie handling with fetch on the server is one of those gaps people only notice after re-implementing it badly a few times. Wrapping tough-cookie behind a plugin and making it transparent at the client level feels like the right abstraction, especially for retry and hedging scenarios. The automatic capture/injection and shared jar support are particularly useful for multi-client or session-based APIs. Exposing the underlying CookieJar directly is also a nice touch for advanced use cases. This looks like a solid solution for anyone who wants browser-like cookie behavior in Node without reinventing the plumbing. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
For anyone building on top of
fetchin Node.js or server side environments and struggling with cookies, I released a small plugin that might help.In the browser, cookies are handled for you.
On the server, if you use
fetch(Node 18+ orundici), you need to:Set-CookieheadersCookieheader per requestI built luminara-cookie-jar, a CookieJar plugin for my HTTP client Luminara, to solve this in a clean way using
tough-cookie.Key points:
Set-Cookiecapture on responsesCookieinjection on requestsCookieJarAPI exposed viaclient.jarfor advanced useMinimal example:
Repo: https://github.com/miller-28/luminara-cookie-jar
npm: https://www.npmjs.com/package/luminara-cookie-jar
If you are using
fetchon the server and need browser-like cookie behavior, this might be useful.Beta Was this translation helpful? Give feedback.
All reactions