Wrapper for isomorphic-fetch that uses internal function calls on server side
We should have a module called idk fuzzy.io-fetch that works mostly like isomorphic-fetch, except if it's running on the server, it would require() and run local functions that give the same output as the endpoints.
Something like this:
fetch = (url) ->
if onTheClient()
fetchOrShim url
else
switch url
when "/plans":
getPlans()
when "/agents"
getAgents()
else
serverSideFetch url
Ideally the handler for exp.get '/plans/'
would use the same getPlans()
function.
There are some tricky parts with passing the authorization state through, and formatting stuff as a Response for fetch, but it's probably worth it so we can have better server-side rendering.