The place to add this to the vendored node-static is probably somewhere in here:
<https://github.com/nodejitsu/http-server/blob/master/vendor/node-static/lib/node-static.js#L66>
Alternately, modifying the finish function itself (wherever it is) may also work.
:+1: I want to load my single page application if the file does not exist on the filesystem
We don't use node-static anymore. Is this possible with ecstatic now @jesusabdullah? I read the code but it wasn't totally obvious to me at a quick skim.
yes, ecstatic does this, and has for some time.
Ok, going to reopen this because we need to expose it through the http-server CLI. Is there an example of how to use this functionality in ecstatic? The option is really illuding me when reading the source.
@jesusabdullah specifically I am talking about custom 404 pages. Maybe that wasn't what you meant when you opened this issue.
Perhaps unrelated but it would be nice to specify an explicit fallback page (i.e. ./index.html) to support almost-static single page applications that change the URL using pushState. I could see that this is outside the scope of your project though...
The issue with using a default 404 page is that the server will still return an error status code in the HTTP response. Since I'm just using http-server as a simple documentation viewer... it's not a big deal.
It's automatic, unless handleError is turned off.
@cmwelsh realize this is a 6 months later, but :+1:! Actually was looking at the repo today to see if this was a planned feature. I love this little server, but I can't use it for my SPA's with "html5mode" on for this reason.
any progress on this?
This works unless you use the -P / --proxy flag.
Single page apps can just symlink index.html -> 404.html and everything works. The server will still respond with a 404 code, but that shouldn't matter in most use cases.
The 404.html file thing has been handled by node-ecstatic for awhile now. I've added a note about it to the README https://github.com/indexzero/http-server/commit/9571d0a84913eb2514d68a9c9600742a0791be83 to close this issue.
Thanks, all!
Most helpful comment
Perhaps unrelated but it would be nice to specify an explicit fallback page (i.e.
./index.html) to support almost-static single page applications that change the URL using pushState. I could see that this is outside the scope of your project though...The issue with using a default 404 page is that the server will still return an error status code in the HTTP response. Since I'm just using
http-serveras a simple documentation viewer... it's not a big deal.