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
@jhwang09 fetchr just helps for isomorphic data fetching – it's not strictly related to a RESTful API.
If you need to read a cookie from a service, you can use the req argument:
varmyService={name: 'myService',read: function(req,resource,params,config,callback){if(req.cookies&&req.cookies.myCookie)// get the cookie from the request// then make a superagent call or whatever};
this is possible only if you create a context on the server passing the req object to it:
// express servervarserver=express();server.use(cookieParser());// make sure it read cookies and attach them `req.cookies`server.use(function(req,res,next){varcontext=app.createContext({req: req,// pass the request to the contextxhrContext: {_csrf: req.csrfToken()}});// go on with server-side rendering);
I didn't see a specific example using it (or I missed it), but it should work.
As for writing a cookie, you need to create it from the browser. For example, a Component.jsx may execute an action onButtonClick which creates a cookie.
Since fetchr is a RESTful API, which should be stateless, so does handling cookie at the client side makes sense?
Also since it's a isomorphic JS app, reading cookie at the server side to dictate the user state also make sense right?
Just want to get these two questions out of my head before I move forward with this approach.
Thanks!
Jerome
The text was updated successfully, but these errors were encountered: