question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with SSR and requestInterceptors

See original GitHub issue

Thanks for this amazing library. It looks great and almost works perfectly! I’m trying to set this up in a SSR NextJS project. I’ve used these instructions from the documentation and SSR works great.

My next step was to add a requestInterceptor so that I don’t have to type the base API domain over and over again. For this I used your example host interceptor. As follows:

const requestHostInterceptor = host => client => async action => {
    return {
        ...action,
        endpoint: `${host}${action.endpoint}`,
    }
}

export const client = createClient({
    cacheProvider: cache,
    requestInterceptors: [requestHostInterceptor('http://local.api.dev')],
})

But SSR stops working as soon as I add the requestInterceptors property to createClient. The endpoint gets called twice (first backend, then frontend again because it finds there is no cache). So the client is making the call correctly from the backend to the api, but somehow the payload remains undefined while rendering on the server.

I’ve looked through the code, but can’t find any pointers. Do you have any ideas?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yoerancommented, Aug 28, 2019

Here is the codesandbox link, not really familiar with codesandbox, so hope it’s correct: https://codesandbox.io/s/react-fetching-library-ssr-nextjs-u5827

0reactions
yoerancommented, Aug 29, 2019

Excellent! Works like a charm. Thanks so much for the quick response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interceptors not work in SSR · Issue #87 - GitHub
It is the problem of plugins' order, i make axios and axios helper plugins called before auth plugin and then all are ok....
Read more >
Logging and error management best practices in SSR apps
Handing SSR errors on the client side · Try…catch blocks · Interceptors for network errors · More tools for handling client-side errors.
Read more >
Angular Server Side Rendering State Transfer For HTTP ...
This tutorial extends the SSR explained on Server-side rendering (SSR) with Angular ... Step 1: Interceptor for SSR to cache HTTP requests.
Read more >
Setting up Axios Interceptors for all HTTP calls in an application
Interceptors are a feature that allows an application to intercept requests or responses before they are handled by the .then() or the .catch() ......
Read more >
Interceptor not intercepting http requests (Angular 6)
In my case interceptor wasn't getting involved for service calls because I had imported HttpClientModule multiple times, for different ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found