Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
125 stars 6 forks source link

Had issue in setup of a S3 + Cloudfront hosting the dist static website #28

Closed stouch closed 2 months ago

stouch commented 2 months ago

I setup my S3 with : index.html as index and error file.

Then I setup my Cloudfront distribution with a Origin Request Lambda@Edge function (node20) like this :

import path  from 'path';
export const handler = async (event, context, callback) => {
  const { request } = event.Records[0].cf;
  const { uri, headers } = request;
  if (uri !== "" && uri !== "/" && !uri.includes('.')) {
      request.uri += '.html';
  }
  return request;
};

And everything worked then.

Thanks for your repo. Actually, it's insane that building a static site is not more obvious/straightforward when we're using react + vite project. Happily you made this repo 🔥 (I created a thread in react.dev about this last part : https://github.com/reactjs/react.dev/issues/7155)

Daydreamer-riri commented 2 months ago

I don't really understand this deployment, I'm glad it worked. If you have any further questions, please let me know.

stouch commented 2 months ago

I had to do this because your lib build the static files as : /my-page.html (instead of /my-page/index.html), and so to tell cloudfront to redirect /my-page to /my-page.html , the above code was necessary.

Daydreamer-riri commented 2 months ago

Oh, this configuration item may help you: https://vite-react-ssg.netlify.app/docs/Configuration#dirstyle