Bukdu.jl icon indicating copy to clipboard operation
Bukdu.jl copied to clipboard

Plug.Static is too sensitive for different paths writing

Open rssdev10 opened this issue 3 years ago • 3 comments

Plug.Static is not providing proper errors.

using Bukdu

routes() do
    # correct way
    plug(Plug.Static, at="/static", from=normpath(joinpath(pwd(),".")))

    # wrong - not able to read from subdirs but able to get from current directory only
    # error in "from" value. For any requested file from subdir, the error 404 is generated.
    plug(Plug.Static, at="/static2", from=pwd())


    # eating symbols from the file name
    # double slash in front of "at"-value gives an exception as a result
    plug(Plug.Static, at="//static3", from=pwd())
end

Bukdu.start(8080)

rssdev10 avatar Sep 15 '22 17:09 rssdev10

please don't use the pwd() to specify the from directory. and what's the meaning about //?

wookay avatar Sep 16 '22 19:09 wookay

If I understand right, the from directory must contain . final symbol. That is unclear.

When the path contains a double slash then file names are interpreted without a first symbol. E.g. plug(Plug.Static, at="//static3", from=pwd()) gives an error while requesting "index.html" => /static3/ndex.html without i. Double slash might be occurring when the path was built from multiple strings with partial paths. Anyway that is not an error.

rssdev10 avatar Sep 16 '22 20:09 rssdev10

Sorry, my suggestion about the . sign was wrong. When normpath() is gettign something ended by /., the result is ended by /. That is, to fix the issue with from just add inside the code normpath(joinpath(normpath(path), ".")) to avoid confusion. Internal normpath() will remove dot if present. Next joinpath will guarantee that the path contains .. And final normpath gives a path that is always ended by /.

To fix the second issue, either change the calculation of the offset, or add replace(uri_path, r"/{2,}" => '/') inside.

rssdev10 avatar Sep 16 '22 23:09 rssdev10