elm-live icon indicating copy to clipboard operation
elm-live copied to clipboard

elm-live assumes any URL ending in .com is a static file

Open glasserc opened this issue 5 years ago • 1 comments

In my project, I have a registration flow that takes the user to a URL like http://localhost:8080/awaiting-confirmation/[email protected]. Doing pushUrl from the Elm side works fine. However, refreshing this page in the browser causes an error: Cannot GET /awaiting-confirmation/[email protected].

I believe this is due to the code here that analyzes the URL to determine what file type the request is trying to get, in order to determine whether to try to serve a static file or to serve the root page:

https://github.com/wking-io/elm-live/blob/e9af6ecee3a8b1ea9261927a1e6c7377505aab3f/lib/src/start.js#L109-L110

Because this is guessing based on the "extension", any URL that ends in .com is assumed to be a static file.

At first I thought this was a problem with the URL parsing in the path component of a URL, so I also tried as a query string: http://localhost:8080/[email protected]. Unfortunately this gave me the same result (Cannot GET /awaiting-confirmation). I don't like the behavior on just paths, but I think the same behavior on query parameters is definitely wrong.

I can think of a few ways we could try to fix this:

  • Instead of guessing that the path is static because of its mimetype, we could assume any path that we can stat() successfully is static.
  • We could be more opinionated about insisting that static assets be located under certain well-known directories such as public or static.

glasserc avatar Jan 09 '20 03:01 glasserc

This is a very good point and something that I didn't have a lot of cases to test the edges of. Would love your thoughts on solutions for this in the code. :)

wking-io avatar Feb 12 '20 16:02 wking-io