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

Static websites fail to rewrite URL for sub directories #192

Closed
tonivdv opened this issue Apr 25, 2022 · 4 comments · Fixed by #202
Closed

Static websites fail to rewrite URL for sub directories #192

tonivdv opened this issue Apr 25, 2022 · 4 comments · Fixed by #202
Labels
bug Something isn't working

Comments

@tonivdv
Copy link

tonivdv commented Apr 25, 2022

Description

I think that since the changes from #175 there is BC break introduced for the 'static-website' type deploy. When deploy a static website that has an index.html in a sub directory , that file will not be loaded automatically anymore. To view to page you have to explicitly provide the index.html in the url.

❌ - https://some-website/sub-directory
✅ - https://some-website/sub-directory/index.html

From what I could see, is that previously the static-website was deployed with the S3 static website feature. Now it doesn't causing it to fail.

How to Reproduce

Deploy a static website with some sub directories and an index.html page in it and deploy like a static website

constructs:
  app:
    type: static-website

If you then open the url with the subdirectory you will get following error:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>XXXX</RequestId>
<HostId>XXXX</HostId>
</Error>

Additional Information

Additionally, the problem is well explained here and with a possible solution.

@tonivdv tonivdv added the bug Something isn't working label Apr 25, 2022
@mnapoli
Copy link
Member

mnapoli commented Apr 27, 2022

Are you sure that https://some-website/sub-directory used to work?

To my knowledge this wasn't supported: you had to use https://some-website/sub-directory/ URLs, but I may be wrong 🤔

@adriencaccia does that ring a bell?

@tonivdv
Copy link
Author

tonivdv commented Apr 27, 2022

@mnapoli I can confirm that in version 1.12.1 this is working. The main difference:

In 1.12.1 we have:

  • s3 bucket that is set to publicly available
  • Static website hosting enabled

In 1.14.0:

  • s3 bucket is not publicly available and only authorises Cloudfront (this is actually a very good improvement)
  • Static website hosting disabled

The solution for 1.14 is to either re-enable static website hosting or to add a lambda for the request event with:

function handler(event) {
    var request = event.request;
    var uri = request.uri;
    
    // Check whether the URI is missing a file name.
    if (uri.endsWith('/')) {
        request.uri += 'index.html';
    } 
    // Check whether the URI is missing a file extension.
    else if (!uri.includes('.')) {
        request.uri += '/index.html';
    }

    return request;
}

I will test this manually and let you know if both or one of the solutions do really work.

But I can confirm that when I deploy my app with version 1.14.0 my app is broken.

@mnapoli
Copy link
Member

mnapoli commented Apr 28, 2022

Right, 1.12.1 introduced support for /directory URLs but that was a side effect of switching from OAI to S3 static website hosting. With prior version that wasn't supported, as we didn't deploy with static websites enabled before.

I still think /directory/ should work though, can you confirm if it doesn't work?

That being said, I'm not against switching static-website back again to S3 website hosting -> since it was the case in 1.12.1 I'm guessing there will be no downside except #172, and #172 was fixed by introducing the single-page-app construct (this construct will not be impacted).

@tonivdv
Copy link
Author

tonivdv commented Apr 28, 2022

I still think /directory/ should work though, can you confirm if it doesn't work?

You are correct, the /directory/ does work. However /directory does not.

That being said, I'm not against switching static-website back again to S3 website hosting -> since it was the case in 1.12.1 I'm guessing there will be no downside except #172, and #172 was fixed by introducing the single-page-app construct (this construct will not be impacted).

I played around a bit and there is something very strange that I can't explain at the moment. When I deploy my app with version 1.12.1, I can see my web page when calling an url with /directory ...

However, when I deploy with 1.14.0, and I manually reconfigure everything exactly the way it is done with 1.12.1, it still refuses to show the page with /directory.

So I really don't understand what is still different underlying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants