stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.04k stars 391 forks source link

HTML output support writing to /ROUTE instead of /ROUTE/index.html #493

Open dougnukem opened 3 years ago

dougnukem commented 3 years ago

Feature Request

Is your feature request related to a problem? Please describe. I want to use react-snap with S3 + CloudFront, but it's problematic to have to setup rules for serving /ROUTE/index.html routes when a user requests just /ROUTE (from what I can tell it requires creating a Lambda@Edge script that runs on every request https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/)

Describe the solution you'd like Ideally react-snap could just generate HTML output as the name of the route e.g. /ROUTE would just generate in output directory build/ build/ROUTE as the HTML.

Describe alternatives you've considered I could write a postbuild script that then converts the ROUTE/index.html to justROUTE, but I'd rather there be a configuration option inreact-snap` to do that.

Teachability, Documentation, Adoption, Migration Strategy If you can, explain how users will be able to use this and possibly write out a version the docs.

To output HTML to the route you want just configure saveAsIndeHtml: false in react-snap in your package.json config.

  "reactSnap": {
    "source": "build",
    "saveAsIndexHtml": false,
    "include": [
      "/",
      "/login"
    ],
    "puppeteerArgs": [
      "--no-sandbox"
    ]
  },
zhusee2 commented 3 years ago

I'm having a similar situation here.

For me I would like to generate /path/to/route.html instead of /path/to/route/index.html, so when hosting via heroku/heroku-buildpack-static it won't be automatically redirected to a route with a trailing slash.

Maybe there can be a separated option to specify extension for output files?

dougnukem commented 3 years ago

Yeah being able to configure the html output name makes sense. I also realized this solution does not make sense for nested paths, because a file can't also be a directory e.g.

I'll alter my PR to allow for configuring the output HTML file name.

I do think the only solution for hosting via S3 + AWS Cloudfront is to use Lambda@Edge scripts to rewrite the requests to serve index.html for subdirectories, using these 2 scripts (would love to hear other simpler solutions that don't require extra Lambdas on every Cloudfront request)

richtier commented 3 years ago

This will help with my scenario: static s3 bucket behind cloudfront. I will try the natahouse fork until it's a vanilla feature

edlt: that helped, but I don't want the .html suffix at all. I will try renaming after react-snap has finished