magidoc-org / magidoc

Autogenerate static GraphQL API documentation
https://magidoc.js.org
MIT License
244 stars 20 forks source link

Hosting on AWS S3 Bucket fails to find subfolders #261

Open felipenedel opened 1 year ago

felipenedel commented 1 year ago

Hi there!

Have anyone hosted the docs on AWS? I'm facing some problems on serving the http from a bucket.

I can use libs like http-server to run it locally without any problems. I've followed the instructions on S3 on how to host static websites, but because of the clean URL's, I had to manually change the root project.html, removing the .html extension, so my index.html could point to the correct file without the suffix. So far it kind of works, but all links only work when I navigate from the root. I can't refresh the page nor manually enter a subfolder path.

For an URL like https://docs.example.com/types/Connection, it issues errors like this:

<Error>
    <Code>NoSuchKey</Code>
    <Message>The specified key does not exist.</Message>
    <Key>types/Connection</Key>
    <RequestId>...</RequestId>
    <HostId>...</HostId>
</Error>

So, since the Connection folder contains an index.html file, I wonder why my S3 Bucket is not recognizing it. And why do I have to manually remove the .html extension? The index.html files are all correctly marked as text/html on their metadata.

There is a similar issue here, regarding Azure (178) but I have no siteRoot prop set.

I'd really appreciate any help!

pelletier197 commented 1 year ago

Hey, sorry for the late reply.

I have personally never tried hosting it on AWS. I could try to look into a way to disable the clean paths for such use-case, I believe this might be possible with Svelte-Kit.

If you ever find a way in the meantime, it would be appreciated if you could open a documentation PR indicating how you achieved it. Thanks!

olirogers commented 10 months ago

I had the same issue with a recent deployment to AWS and managed to solve it by following an idea posted here:

  1. magidoc generate -> creates docs folder
  2. Extract all html files to a different folder (in the same folder structure)
  3. Rename filename.html -> filename in this new folder
  4. Use aws CLI to sync docs folder with delete option e.g. aws s3 sync docs s3://<bucket>/api/graphql/ --delete
  5. Use aws CLI to sync html folder without delete option but setting content-type to 'text/html' e.g. aws s3 sync build/html s3://<bucket>/api/graphql/ --content-type "text/html"

It's a bit convoluted but easily scriptable. There might be a way to force AWS to add the suffix .html to files but I could only find redirect options for prefixes.

felipenedel commented 10 months ago

@olirogers Thank you very much for your reply! I'm going on vacation soon but when I return I will try it out!