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.

SSR and CSR confusion

See original GitHub issue

Hi,

Little confused with proxying requests.

Currently I cannot get both SSR and CSR working at the same time, but can get them working individually.

Request: return $axios.get( '/pages/123' )

Config: nuxt.config.js

axios: {
	proxy: true,
	proxyHeaders: false,
	baseURL: process.env.NODE_ENV === 'development' ? 'http://local-api.test/wp-json/wp/v2' : 'https://user:pass@live-api.com/wp-json/wp/v2',
},
proxy: {
	'/data/': {
		target: process.env.NODE_ENV === 'development' ? 'http://local-api.test/wp-json/wp/v2' : 'https://user:pass@live-api.com/wp-json/wp/v2',
		pathRewrite: {
			'^/data/': '/'
		}
	}
},

SSR will correctly fetch 123 route and render. However, if I go to another page and go back to this page and fetch via CSR, then it will request incorrectly to a page, not a endpoint.

However, if I change the request from return $axios.get( '/pages/123' ) to return $axios.get( '/data/pages/123' ), CSR will work correctly, but SSR will 404 Request failed with status code 404.

How can I get both CSR and SSR working?

Thanks, Tom

<div align="right">This question is available on Nuxt community (#c257)</div>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
codeofsumitcommented, Jul 16, 2019

oh sh*t no, you just made me realize it has been working all along. The proxying is hidden in the background. The errors I got were from the API (just as I wanted) but I did not realize this. 🎉 🎉 => it works!

Thanks so much for you quick answers 😅 I’m very happy again

0reactions
CHEWXcommented, Jul 16, 2019

Haha, no worries dude!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering (SSR) vs. Client Side Rendering (CSR ...
CSR or SSR “rendering” should not be confused with “web page rendering” that is performed by a browser engine (like Webkit, Blink, Gecko,...
Read more >
SSR vs CSR: Which Method Works Best? - Growth Rocket
In case you're still feeling confused, it helps to think of SSR as you driving over to the supermarket every time you feel...
Read more >
The Ultimate Metaphor for SSR, CSR and Pre-Rendering
I hope that you find this metaphor clear enough and you use it with people who might confuse one or the other. If...
Read more >
Server-Side Rendering (SSR) Vs Client-Side Rendering (CSR)
In SSR, when the user makes a request to the webpage, the server prepares the HTML ... The final call is yours whether...
Read more >
Understanding Next.js Data Fetching (CSR, SSR, SSG, ISR)
It is quite confusing because when using Create React App, we usually only use 1 strategy to fetch data from API which is...
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