-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for custom 404 error pages #126
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 error pages #126
Conversation
beaa717 to
44f7075
Compare
patrickdappollonio
left a comment
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.
This is great, Muse!
The last thing I would ask is, http-server often lets you know if something was configured. To do so, would you mind also printing in the PrintStartup() function the fact you're starting using a custom 404 error page?
Something along the lines of:
if s.CustomNotFound != "" {
fmt.Fprintln(s.LogOutput, "Using custom 404 page:", s.CustomNotFound)
}|
Thank you for the review Patrick. Made changes as requested. |
patrickdappollonio
left a comment
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.
Got an extra comment from an acquaintance that uses this project at a well known company which I think we will need to document as an edge case scenario:
When http-server starts, we check if the file is there. Imagine http-server is running for a week, and when you started it, you used --custom-not-found-page=404.html. There could be a situation where the 404 file gets deleted (say, you remounted the directory but for some reason your build process deleted the 404 file) and now you're left wondering what happened that your error page is no longer there.
I think to me that's an acceptable situation. The alternative would be to load the file at the beginning, but that means if you end up updating that file, then the server would need to be restarted for it to take effect.
Today, we have a similar situation with the _redirections file: there is no way to update the redirections file without restarting the server, since the rules get processed on server start.
I do believe though it's acceptable in this case to read a file, and if you deleted it, return the real 404 page (which doesn't have much bells-and-whistles) instead of the customized one.
All that to say, one last change and I'm down to merge this!
|
Tried the new code and unfortunately we'll have a few issues due to
On a first request: Then for the follow-up request (emulating a browser that's sending the etag back to the server): The first one, while nice, should come after #120's "custom status codes"... Not right away. For the second one, I'm torn. For people that want an SPA (see #7), getting the cached copy is actually beneficial (speed improvement) but I'm not sure what's the overall consensus everywhere else. Will have to look at what other To solve the first part (and potentially the 2nd part) we might have to create either a custom version of We could write a response hijacker that no-ops the status code, since that would have to be solved for #7 as well. I'll cook something up. |
|
Last note: It's missing the documentation, namely updating the help output here: https://github.com/patrickdappollonio/http-server/blob/master/README.md?plain=1#L48-L75 We can avoid a longer documentation in favour of whenever the actual full feature (including custom status codes) happens to be. |
Co-authored-by: Patrick D'appollonio <930925+patrickdappollonio@users.noreply.github.com>
5ff5ba1 to
6cb101a
Compare
patrickdappollonio
left a comment
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.
Looks good to me!
Fixes #120. Custom 404 page can be passed with
--custom-not-found-page