Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server side rendering #2530

Closed
Vadorequest opened this issue Jun 13, 2017 · 7 comments
Closed

Server side rendering #2530

Vadorequest opened this issue Jun 13, 2017 · 7 comments

Comments

@Vadorequest
Copy link

Hello, I just opened a SO question about how to do SSR with create-react-app. I'm not particularly looking for SSR, maybe another solution would work for me. (Like templating, or variable injection)

https://stackoverflow.com/questions/44472024/how-to-use-server-side-rendering-with-create-react-app

Thanks.

@peterbe
Copy link

peterbe commented Jun 15, 2017

What is the issue? How do you expect this to be actionable?

@Timer
Copy link
Contributor

Timer commented Jun 15, 2017

I'm going to close this because it seems you have answers on the SO question.
However, the most relevant section of our docs is probably this.

@Vadorequest
Copy link
Author

@Timer Actually, there was no useful answer given on SO and my post got closed.

I also think the data injection is the way to go, but I don't understand how it works, how do you set the __SERVER_DATA__ in the given example? There is a lot of things done under the hood and I don't quite understand how to implement it. But yeah, it would be enough for my needs actually, no need for SSR.

@Timer
Copy link
Contributor

Timer commented Jun 15, 2017

This section has a snippet about it:

Then, on the server, regardless of the backend you use, you can read index.html into memory and replace __OG_TITLE__, __OG_DESCRIPTION__, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML!

Basically, read index.html from the disk and replace it using your preferred method.

@Vadorequest
Copy link
Author

I use npm run start cli command to lift my dev server. This is all managed by react-scripts, how am I supposed to do this replace thing then? On production, I can probably do it after the npm run build, but I need an identical process between dev and prod. Maybe I'm missing something?

@Timer
Copy link
Contributor

Timer commented Jun 15, 2017

See #1703.

@leoskyrocker
Copy link

@Vadorequest not sure if this helps, but here's an example of how to do the server side templating: https://stackoverflow.com/a/38129612/2461213

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants