elm-live
elm-live copied to clipboard
Don't consider nonexistant files as static
Fixes #209.
- Only examine URL
pathname
when deciding whether a request should be handled statically. - If a file does not exist, don't try to serve it statically.
I'm pretty sure that the first fix, where we no longer regard the query string when examining what to do with a path, is good and correct.
However, having implemented the behavior where we only consider serving a file statically if it actually exists, I'm not sure how I actually like it. This behavior means we serve a 200 with a gibberish response on any incorrect path to an asset, which makes certain problems harder to find. On the other hand, it doesn't seem unreasonable for an Elm application to want to masquerade as e.g. ASP.NET or PHP, in which case it might want to serve URLs that end in e.g. .aspx
or .php
. It might make sense to carve out exceptions for certain well-known file types such as CSS, JS, .ico
, .png
, .jpg
, or alternately revert this behavior entirely and make people like me put email addresses as query string arguments instead of paths. Thoughts?
I also ought to mention that the nginx configuration I was going to put in production says try_files $uri $uri/ index.html
, so at least I'm consistent :joy:. I'm not really sure how else I would implement a configuration for a SPA which would exclude things like favicon.ico
unless I specified them explicitly (in which case I might as well just create a real file to use to fulfill those requests). So I guess I'm comfortable with a solution like the one I implemented in this PR.