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

Add support for custom 404 document #38

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

ThorstenHans
Copy link
Contributor

With this PR spin-fileserver can be configured to serve a custom 404 document instead of returning the default 404 Not Found response using the CUSTOM_404_PATH environment variable.

If the path specified in CUSTOM_404_PATH doesn't exist, the default 404 Not Found response is returned to the user.

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of non-blocking suggestions and clarifications.

readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated
@@ -60,6 +60,19 @@ files = [{ source = "test", destination = "/" }]
environment = { FALLBACK_PATH = "index.html" }
```

### Using a custom 404 document

You can configure a `CUSTOM_404_PATH` environment variable that points to a file that will be served instead of returning a plain 404 Not Found response. If the `CUSTOM_404_PATH` environment variable is not set or points to a non-existing file, the default 404 Not Found response is returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly worth noting that the custom 404 file has to be included as an asset. (This might not "just happen" if, say, the file server was configured to serve the /images directory instead of the whole site.) And that the path is the mount path inside the fileserver component. (In your example, the source file would have to be test/custom-404.html in order to get mounted as custom-404.html.)

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've rewritten the paragraph, maybe you can check again @itowlson

Copy link
Member

@radu-matei radu-matei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for your contribution, @ThorstenHans!

@radu-matei radu-matei merged commit 308d842 into fermyon:main Aug 28, 2023
2 checks passed
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.

3 participants