Mux.ClosureType
Closure

Mux doesn't really use this type, we just print Mux.Closure instead of Mux.var"#1#2{Mux.var"#3#4"{...}} in stacktraces to make them easier to read.

Mux.filesFunction
files(root, dirs=true)

Middleware to serve files in the directory specified by the absolute path root.

req[:path] will be combined with root to yield a filepath. If the filepath is contained within root (after normalisation) and refers to an existing file (or directory if dirs=true), then respond with the file (or a directory listing), otherwise call the next middleware.

If you'd like to specify a root relative to your current working directory or to the directory containing the file that your server is defined in, then you can use pwd() or @__DIR__, and (if you need them) joinpath or normpath.

Examples

files(pwd()) # serve files from the current working directory
files(@__DIR__) # serve files from the directory the script is in

# serve files from the assets directory in the same directory the script is in:
files(joinpath(@__DIR__, "assets"))

# serve files from the assets directory in the directory above the directory the script is in:
files(normpath(@__DIR__, "../assets))
Mux.find_closing_charMethod
find_matching_index(str, idx, closing_char)

Find the index in str of the matching closing_char for the opening character at idx, or nothing if there is no matching character.

If there is a matching character, str[idx:find_matching_index(str, idx, closing_char)] will contain:

  • n opening characters, where 1 ≤ n
  • m closing characters, where 1 ≤ m ≤ n

The interior opening and closing characters need not be balanced.

Examples

julia> find_closing_char("((()))", 1, ')')
6

julia> find_closing_char("Vector{Union{Int64, Float64}}()", 7, '}')
29
Mux.mux_showerrorMethod
mux_showerror(io, exc, bt)

showerror(io, exc, bt), but simplify the printing of all those Mux closures.

Mux.rename_mux_closuresMethod
rename_mux_closures(str)

Replace all anonymous "Mux.var" closures in str with "Mux.Closure" to make backtraces easier to read.

Mux.serveFunction
serve(h::App, w::App, host=0.0.0.0, port=8000; kwargs...)
serve(h::App, w::App, port::Integer; kwargs...)

Start a server that uses h to serve regular HTTP requests and w to serve WebSocket requests.

Mux.serveFunction
serve(h::App, host=0.0.0.0, port=8000; kws...)
serve(h::App, port::Int; kws...)

Serve the app h at the specified host and port. Keyword arguments are passed to HTTP.serve.

Starts an async Task. Call wait(serve(...)) in scripts where you want Julia to wait until the server is terminated.