-
Notifications
You must be signed in to change notification settings - Fork 71
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
Implement Feature Request: Add custom fields to define index and error documents #20
Conversation
… 'spa' parameter to redirect errors to index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanseeds only one substantial question. After you answer that we can make changes here and get this into the next release.
README.md
Outdated
@@ -22,10 +22,15 @@ custom: | |||
client: | |||
bucketName: unique-s3-bucketname-for-your-website-files | |||
distributionFolder: client/dist # (Optional) The location of your website. This defaults to client/dist | |||
indexDocument: index.html # (Optional) The location of your index document. Defaults to index.html | |||
errorDocument: error.html # (Optional) The location of your error document. Defaults to error.html | |||
spa: false # (Optional) Set this for single-page applications to redirect all errors to the index document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanseeds Is there a benefit to adding this extra configuration value over just letting the user set both the index and error document to index.html?
It seems like it's an extra config value? Here's what I mean:
This:
indexDocument: index.html
spa: true
Is the same expected outcome as this:
indexDocument: index.html
errorDocument: index.html
Any objection to removing the spa option? I'm open to it with valid use-case. I might just not understand it presently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My use case is using finch to deploy single-page applications that need all traffic redirected to index.html. This allows the webapp in the index.html file to handle all routes. I think it's more intuitive to be able to just set a 'spa' flag to true. Otherwise, a user would be to have to figure out how to implement this feature in S3, and then how to translate those S3 settings into finch.
In most of these cases you would be using the default 'index.html' indexDocument, and so the config comparison would be:
spa: true
vs
indexDocument: index.html
errorDocument: index.html
The specific changes being made are more obvious in the second, but I think having the first option is more user-friendly.
'spa' may not be the best name, for sure. 'singlePage' or 'singlePageApplication' would be clearer names. Alternative, a more descriptive name like 'redirectErrorsToIndex' may work too.
Ultimately, there's a part of me that just doesn't like having to write the same thing twice, but maybe that's just an obsession 😅
README.md
Outdated
``` | ||
|
||
* **Warning:** The plugin will overwrite any data you have in the bucket name you set above if it already exists. | ||
|
||
* **Warning:** If the 'spa' option is set, the errorDocument setting will be ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If spa: true
the errorDocument will be ignored.
See my above comment on related to the spa
config value.
README.md
Outdated
@@ -76,5 +81,6 @@ serverless client remove | |||
- [amsross](https://github.com/amsross) | |||
- [pradel](https://github.com/pradel) | |||
- [daguix](https://github.com/daguix) | |||
- [evanseeds](https://github.com/evanseeds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for saving me the work 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to be thorough 😅
Once this PR is merged, approximately how soon after would it be in a release? I'm eagerly awaiting this feature. |
I think the SPA option may be a bit confusing and more difficult to write tests for in the future (which I'm trying to move towards as development on this increases) For now, I'm going to remove that option but I'm open to revisiting the decision in the future. The two options this adds (without the spa option) should be enough to get the same functionality. |
@evanseeds can you test this again? I'm seeing an error. Testing using a simple config:
@stefan2718 once I'm sure this doesn't have any bugs I'll ship it. You're welcome to help write tests to help catch things like this! Unfortunately, manual tests take a while. |
I updated it to remove the spa option and fixed that bug as well. It should be good now! |
@evanseeds tested and merged. Checking a few things and pushing a new version to npm. |
How about an option to specify the HTTP code when returning the errorDocument? Since I'm hosting a SPA on s3, I want it to be 200. |
Thanks for the question @akinnee. You're welcome to open a new issue for this or a PR that implements the functionality. I'm not entirely sure how that would work as I think S3 handles the codes returned from the site and I don't know of a way to customize those codes. But if you're aware of a way to do this please open an issue and we can look into it! |
Added three .yml options: 'indexDocument' and 'errorDocument', which allow customizing the s3 bucket option for each, and 'spa', which automatically sets the errorDocument to be the indexDocument, overriding the errorDocument .yml setting if both are set.
This implements the issue at #16