Bukdu.jl
Bukdu.jl copied to clipboard
New generated image doesn't display in browser
At first, I thought I could use the images as static files. If I added them to the public folder I only got to see them when I restarted the Bukdu server.
Then I changed the code as you see below by uncommenting the static route and added a . before /$(params.image)'. Next, I created a new image in the root folder while the server was running. Unfortunately, that didn't work either.
Question: How can I show new images in a browser?
function myimage(c::WebController)
params = c.conn.path_params
render(HTML, "<img src='./$(params.image)' />")
end
routes() do
get("/img/:image", WebController, myimage)
#plug(Plug.Static, at="/", from=normpath(@__DIR__, "public"))
end
when you created the new image in the public folder,
you must to update the routes by call routes again.
routes() do
plug(Plug.Static, at="/", from=normpath(@__DIR__, "public"))
end
I fixed the CLI.routes() results in the master branch.
(@v1.5) pkg> dev Bukdu
Were these the right steps?
I cloned Bukdu with ] dev Bukdu, and did cd ~/.julia/dev/Bukdu/. Then started Julia 1.5.3, activated the folder, and ran the Bukdu server. Next, I copied image22.jpg into public and refreshed the browser. The image became only visible after refreshing the routes() do code.
I moved image22.jpg back to the root folder, renamed it image23.jpg, and moved it back into the public folder. Then I ran CLI.routes(). I expected that the image would be shown but it did not.
julia> TEST: image23.jpg
INFO: GET WebController myimage 200 /img/image23.jpg
INFO: GET MissingController not_found 404 /image23.jpg
julia> CLI.routes()
GET /img/:image WebController myimage
GET /image22.jpg StaticController readfile
shell> ls public/
image23.jpg
try again routes for every changes in public folder.
routes() do
plug(Plug.Static, at="/", from=normpath(@__DIR__, "public"))
end
you could watch_folder, FolderMonitor to update automatically.
- https://docs.julialang.org/en/v1/stdlib/FileWatching/#FileWatching.watch_folder
- https://github.com/wookay/Bukdu.jl/issues/47#issuecomment-397980725
Thank you, @wookay.
My final solution is:
using FileWatching
@async while true
FileWatching.watch_folder("./public")
routes() do
plug(Plug.Static, at="/", from=normpath(@__DIR__, "public"))
end
end