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

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

Open
dougnukem opened this issue Aug 31, 2020 · 3 comments
Open

Comments

@dougnukem
Copy link

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 just ROUTE, but I'd rather there be a configuration option in react-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
Copy link

zhusee2 commented Sep 2, 2020

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
Copy link
Author

dougnukem commented Sep 2, 2020

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.

  • /about -> creates HTML file /about
  • /about/doug -> creates HTML file /about/doug FAILS to write this out because /about is a file.

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
Copy link

richtier commented Dec 26, 2020

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

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