Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

How to expose express req/res objects to node-wpapi #77

Closed
MickeyKay opened this issue Jan 9, 2018 · 6 comments
Closed

How to expose express req/res objects to node-wpapi #77

MickeyKay opened this issue Jan 9, 2018 · 6 comments

Comments

@MickeyKay
Copy link

MickeyKay commented Jan 9, 2018

Is there a way to pass our express app's req/res objects to Kasia, specifically within our node-wpapi instance?

We've trying to hook up node-redis middleware for server-side caching, and the cache instance gets passed through on the req object. I'm thinking we can create a custom transport method ala https://github.com/WP-API/node-wpapi#customizing-http-request-behavior and then check for the existence of the cache instance to bypass doing an actual fetch, however to do this we need to be able to check the req object. Any ideas? Thanks!

@sdgluck
Copy link
Contributor

sdgluck commented Jan 10, 2018

This isn't possible currently, but wouldn't take much to implement, at least for SSR anyway. Creating a dummy request object on the client would be bit more work, if desirable. For the former only (access to req during SSR), this would require a simple change to the preload function, which could be passed the req object as an argument and pass this into the queryFn, where you could do whatever you like with it. Happy to take PRs for that, otherwise I will take a look into it ASAP. We are well overdue for the release of v4.2 as well, so we could bundle it into that.

@MickeyKay
Copy link
Author

MickeyKay commented Jan 10, 2018

Thanks @sdgluck, I probably don't have the bandwidth to take this on any time soon, but will definitely circle back if time opens up for me. Thanks for the quick response, excited to see the continued development of this great project.

@sdgluck
Copy link
Contributor

sdgluck commented Jan 24, 2018

@MickeyKay Can I confirm that when you say "pass req/res objects to Kasia", you mean in order to access them in a connected component's query function?

@MickeyKay
Copy link
Author

Possibly. More specifically, the idea would be to instantiate our backing node-wpapi object with a custom transport method hooked into a node-redis instance. That way, we have a secondary cache that can short-circuit external requests across sessions, as opposed to Kasia's single-session "caching" logic (in which objects already in the store are not re-requested).

@sdgluck
Copy link
Contributor

sdgluck commented Feb 2, 2018

In that case I'm not sure I understand what functionality you are asking to see in Kasia. Could you give an example of the kind of API you're looking for?

@MickeyKay
Copy link
Author

Yeah, I'm thinking this is probably less a Kasia-specific question and more a general wp-api question. This is newer territory for me, so thanks for your patience :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants