3 ms·
Yeah, I understood what you wanted. I may not have been clear in my line of thinking. My understanding is that react-server does not support this. However, I do
by wwalser 10y ago
Yeah, I understood what you wanted. I may not have been clear in my line of thinking. My understanding is that react-server does not support this. However, I do not believe that it would be difficult to add support using the testing plugins built for SuperAgent.
Imagine writing tests with mocked requests. Now apply that same logic to all calls to fetch() on the server. Does that make sense?
So to the front end when fetch() is called, it actually makes the request. On the server, when fetch() is called it hits a mock plugin which fetches "mocked" data which is just fetching data from whatever local store you normally would on your backend be it a JSON blob on the file system, a database or an in memory cache.
editing to say that @exogen gave what may be a better explanation below: https://news.ycombinator.com/item?id=12273029 https://news.ycombinator.com/item?id=12273029
- chadscira 10y agoAnother universal http option is : https://github.com/matthew-andrews/isomorphic-fetch https://github.com/matthew-andrews/isomorphic-fetch
- wwalser 10y agoThat's the opposite of what the question is asking for. They want to call fetch('/api/foo/bar') but on the client it does an HTTP call while on the server it recognizes that /api* is on the local system and therefore invoke that local route instead of doing an unnecessary http call. That's what I'm apparently failing to describe how to accomplish :).
- chadscira 10y agoOh i see, I actually accomplished that a while back by monkey patching superagent to use Hapi.js, and inject.