You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently it provides a way to add middleware for fetching process.
Middleware is just a function that receives:
Request - request object created from fetch payload
Next - function that receives Request and returns Promise<Response>
Middleware should return Response | Promise<Response>
In fetch-tools package there is a simple middleware for collect cookie on the server. But recently I realized that I did not implement it quite correctly.
I see that fetch-cookie makes a lot of work to collect/pass cookie according to spec and browser behavior
Can i create properly worked solution based on fetch-cookie as middleware?
The text was updated successfully, but these errors were encountered:
import{Middleware}from'@krutoo/fetch-tools';interfaceCookieStore{// ...}exportfunctioncookieMiddleware(store: CookieStore): Middleware{returnasync(request,next)=>{constnextHeaders=newHeaders(request.headers);// here we get cookies from the storage that are needed only for this requestnextHeaders.append('cookie',store.getCookies(request));// copy original request with add cookieconstnextRequest=newRequest(request,{headers: nextHeaders})// make fetchconstresponse=awaitnext(nextRequest);// handle set-cookie headersif(response.headers.has('set-cookie')){response.headers.forEach((headerValue,headerName)=>{if(headerName==='set-cookie'){store.setCookie(headerValue);}});}returnresponse;};}
Hi, i develop some library for fetch function - fetch-tools:
https://github.com/krutoo/fetch-tools
Currently it provides a way to add middleware for fetching process.
Middleware is just a function that receives:
Request
- request object created from fetch payloadNext
- function that receives Request and returnsPromise<Response>
Middleware should return
Response | Promise<Response>
In fetch-tools package there is a simple middleware for collect cookie on the server. But recently I realized that I did not implement it quite correctly.
I see that fetch-cookie makes a lot of work to collect/pass cookie according to spec and browser behavior
Can i create properly worked solution based on fetch-cookie as middleware?
The text was updated successfully, but these errors were encountered: