Bukdu, how to display favicon.ico

I have built a simple website with Bukdu. It works fine, except that it gives a 404 error message because it does not find favicon.ico. favicon.ico is stored in the base directory.

Bukdu Listening on 0.0.0.0:8004
INFO: GET     WebController       index           200 /
INFO: GET     MissingController   not_found       404 /favicon.ico

I am running the application from a notebook. The routes are:

routes() do
  get("/", WebController, index) # the index function is defined in the file functions.jl
  get("/agingreport", WebController, aging_report)
  get("/gl", WebController, gl)
end;

Tried to define an extra route but was not successful. How could I solve this?

1 Like

you could plug the Static plugin.

plug(::Type{Static}; at::String, from::String, only::Union{Vector{String},Nothing}=nothing, indexfile="index.html")

see some examples:

@wookyoung, thank you. It works great.

I created a folder public with favicon.ico and changed the routes as follows:

routes() do
  get("/", WebController, index)
  get("/agingreport", WebController, aging_report)
  get("/gl", WebController, gl)
  plug(Plug.Static, at="/", from=normpath(@__DIR__, "public"))
end

Output:

Bukdu Listening on 0.0.0.0:8000
INFO: GET     WebController       index           200 /
INFO: GET     StaticController    readfile        200 /favicon.ico
INFO: GET     WebController       aging_report    200 /agingreport