You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
@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.
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.
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?
Activity
peterbe commentedon Jun 15, 2017
What is the issue? How do you expect this to be actionable?
Timer commentedon 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 commentedon Jun 15, 2017
@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 commentedon Jun 15, 2017
This section has a snippet about it:
Basically, read
index.htmlfrom the disk and replace it using your preferred method.Vadorequest commentedon Jun 15, 2017
I use
npm run startcli 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 thenpm run build, but I need an identical process between dev and prod. Maybe I'm missing something?Timer commentedon Jun 15, 2017
See #1703.
leoskyrocker commentedon Jul 10, 2017
@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