getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 111 forks source link

Default html file for subdirectory #285

Closed esimonetti closed 1 year ago

esimonetti commented 1 year ago

Start from the Use-case

Ability to have subdirectories serving a default static file

Say that I have a subdirectory called "static" Static contains an index.html file. If I access https://mysite.com/static I get an error. If I access https://mysite.com/static/index.html I get the correct page/html file.

Is there a way to define what page to load by default, similarly to what happens for errorPage?

Thanks!

Example Config

constructs: website: type: server-side-website assets: '/static/*': static

Implementation Idea

Would it be possible to do something similar to errorPage https://github.com/getlift/lift/blob/163514966829cd5e1152011a3bdbe40e6d97b793/src/constructs/aws/ServerSideWebsite.ts#L55 ?

piolet commented 1 year ago

Hello, maybe it's the same issue as #94 ?

esimonetti commented 1 year ago

Hi @piolet indeed. Sorry for the duplication. Perhaps not sure if it is possible, there could be a default per folder?

For now I have managed to extend cloudformation to trick 403 errors with a static page, but it is more of a workaround than anything else.

If anyone is interested:

        # customising cloud formation for the distribution, to handle 403 with different pages (in our case the static website page)
        extensions:
          distribution:
            Properties:
              DistributionConfig:
                CustomErrorResponses:
                  - ErrorCachingMinTTL: 0
                    ErrorCode: 403
                    ResponseCode: 200
                    ResponsePagePath: /static/index.html
                  - ErrorCachingMinTTL: 0
                    ErrorCode: 500
                  - ErrorCachingMinTTL: 0
                    ErrorCode: 504
piolet commented 1 year ago

From myside, i fixed this kind of issue with specific assets like this :

      '/folder/index.html': build/folder/index.html
      '/folder/': build/folder/index.html
      '/folder': build/folder/index.html

And this for each subfolder. In my case, it's possible because folder are countable. But maybe in your case, it's not possible.

mnapoli commented 1 year ago

Closing as duplicate of #94 then. @piolet interesting workaround!

esimonetti commented 1 year ago

From myside, i fixed this kind of issue with specific assets like this :

      '/folder/index.html': build/folder/index.html
      '/folder/': build/folder/index.html
      '/folder': build/folder/index.html

And this for each subfolder. In my case, it's possible because folder are countable. But maybe in your case, it's not possible.

Thank you @piolet for the suggestion! Personally I could not get this approach to work, and have been trying all possible combinations I could think. I am not sure at this stage