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

create-react-app serve 200.html #447

Open
s0l0ist opened this issue Mar 4, 2020 · 2 comments
Open

create-react-app serve 200.html #447

s0l0ist opened this issue Mar 4, 2020 · 2 comments

Comments

@s0l0ist
Copy link

s0l0ist commented Mar 4, 2020

Feature Request

Is your feature request related to a problem? Please describe.
Related to #117 - not a problem, just more clarification on how to serve 200.html in the readme to prevent index.html flashing.

Describe the solution you'd like
A section dedicated to common static services and how to properly configure them.

Describe alternatives you've considered
Leaving the readme as-is

Teachability, Documentation, Adoption, Migration Strategy
Describe a couple of use-cases for serving static sites with react-snap and redirecting to 200.html
Specifically, describe a few configurations for Nginx and the recommended serve -s build from create-react-app.

For Nginx, this is a simple configuration change:

server {
    ...
    root /var/www/my-site;
    index index.html;
    ...
    location / {
      # If SPA (no ssr) , serve index.html
      # try_files $uri /index.html;
      # React-snap, serve 200.html
      try_files $uri /200.html;
    }
}

For create-react-app's suggestion to use serve -s build:

  • add a serve.json file containing the following:
{
  "rewrites": [{
    "source": "**",
    "destination": "200.html"
  }]
}
  • Modify the serve script in package.json to be:
    "serve": "serve -c serve.json build",
@Daniel15
Copy link

Daniel15 commented Apr 20, 2020

try_files $uri /200.html;

This will serve 200.html even for 404 errors though, so the 404.html file will never be used and the response header will never have 404 File Not Found as the status.

It will alos

You probably want something like $uri.html $uri/index.html in your try_files so that requests to /foo/ (for example) serve either the /foo.html or /foo/index.html files if one exists, and only fall back to /200.html if they don't.

@Daniel15
Copy link

Daniel15 commented Apr 20, 2020

I was thinking about this more, and directly serving the files via Nginx isn't optimal at the moment, as it's tricky to configure HTTP/2 push correctly using the http2-push-manifest.json. That'd be possible with a Lua script (as per #73) or by using code generation to generate the correct Nginx config, eg:

location = / {
  http2_push /static/js/main.xxxxxxx.chunk.js;
  http2_push /static/js/1.xxxxxxx.chunk.js;
}

location = /about/ {
  http2_push /static/js/main.xxxxxxx.chunk.js;
  http2_push /static/js/2.xxxxxxx.chunk.js;
}

but in the end, for my particular use case I just made my backend server (using ASP.NET Core) handle it as that was the easiest approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants