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

Implement Feature Request: Add custom fields to define index and error documents #20

Merged
merged 4 commits into from
Feb 13, 2018

Conversation

evanseeds
Copy link
Contributor

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

Copy link
Owner

@fernando-mc fernando-mc left a 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
Copy link
Owner

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.

Copy link
Contributor Author

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.
Copy link
Owner

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)
Copy link
Owner

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 😉

Copy link
Contributor Author

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 😅

@stefan2718
Copy link

Once this PR is merged, approximately how soon after would it be in a release? I'm eagerly awaiting this feature.

@fernando-mc
Copy link
Owner

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.

@fernando-mc
Copy link
Owner

@evanseeds can you test this again? I'm seeing an error. Testing using a simple config:

service: serverless-finch-test

provider:
  name: aws
  runtime: nodejs6.10

plugins:
  - serverless-finch

custom:
  client:
    bucketName: my-serverless-finch-test-eu-west-3-test
    distributionFolder: website
    indexDocument: index.html
    errorDocument: error.html

./website contains the index.html and error.html files. I would expect this to work but somehow the indexdoc variable is undefined at that time.

ReferenceError: indexdoc is not defined
    at Client.configureBucket (/home/fernando/Documents/code/test-serverless-finch/node_modules/serverless-finch/index.js:193:18)

@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.

@evanseeds
Copy link
Contributor Author

I updated it to remove the spa option and fixed that bug as well. It should be good now!

@fernando-mc fernando-mc merged commit c84fdc7 into fernando-mc:master Feb 13, 2018
@fernando-mc
Copy link
Owner

@evanseeds tested and merged. Checking a few things and pushing a new version to npm.

@akinnee
Copy link

akinnee commented Aug 13, 2018

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.

@fernando-mc
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants