kettle11 / devserver

A simple HTTPS server for local development. Implemented in Rust.
zlib License
95 stars 15 forks source link

404 page #12

Open kettle11 opened 4 years ago

kettle11 commented 4 years ago

Right now if a .html file is not found devserver returns a 404, but it would be more easily noticed if a 404.html page were served.

Additionally with the current behavior if a page is quickly removed and then it's possible that devserver will refresh in the middle and return a 404 breaking development flow. A proper 404.html page would have the embedded reload script and so it would properly refresh to the final page.

A partial mitigation was proposed and implemented in this issue: https://github.com/kettle11/devserver/issues/11. This mitigation does not fully solve the issue. If File A is deleted then added and File B is modified then File A could still return a 404 and the browser returns a page without the refresh script.

Many users developing static websites may have their own custom 404 page. A brief survey of existing development servers should be done to learn what the status quo for serving 404 pages is. Do they offer a flag to specify the path to the 404 file?

bbros-dev commented 3 years ago

Thank you for the effort put into making devserver - and for making it open source. It is appreciated.

It seems other devservers can do some funky things.... take the webpack dev server:

....
ℹ 「wds」: 404s will fallback to /index.html`

As reported on SO

cw789 commented 3 years ago

I would return a really simple 404.html (or string). Not as flag with path to file. Never saw this with dev servers.

The funky thing to always return index.html is used for developing SPAs (single page applications), where the application does all the routing. That as a flag (--spa) would be probably be beneficial.

But keep it simple - for static websites it's really wonderful as it is.

mradke commented 1 year ago

I think this feature is nicely covered by Devd: https://github.com/cortesi/devd#serving-default-content-for-files-not-found The gist is that you pass a --notfound flag where you can specify which file should be served instead if something cannot be found.

Would you accept a pull request @kettle11? Then I'd like to take a stab at it, since I would need this for single pages applications.

kettle11 commented 1 year ago

@mradke I’d accept that pull request. Let me know if you run into issues.