Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New generated image doesn't display in browser #113

Open
rbontekoe opened this issue Feb 9, 2021 · 4 comments
Open

New generated image doesn't display in browser #113

rbontekoe opened this issue Feb 9, 2021 · 4 comments

Comments

@rbontekoe
Copy link

rbontekoe commented Feb 9, 2021

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
@wookay wookay mentioned this issue Feb 9, 2021
@wookay
Copy link
Owner

wookay commented Feb 9, 2021

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

@rbontekoe
Copy link
Author

rbontekoe commented Feb 10, 2021

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

@wookay
Copy link
Owner

wookay commented Feb 11, 2021

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.

@rbontekoe
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants