Skip to content

Commit 694d9b2

Browse files
SimonDanischshashi
authored andcommitted
add generic show method
1 parent e367eee commit 694d9b2

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/providers/generic_http.jl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ kill!(server::WebIOServer) = put!(server.server.in, HTTP.Servers.KILL)
6767

6868
const singleton_instance = Ref{WebIOServer}()
6969

70-
7170
"""
7271
WebIOServer(
7372
default_response::Function = ()-> "";
@@ -130,12 +129,13 @@ usage:
130129
"""
131130
function WebIOServer(
132131
default_response::Function = (req)-> missing;
133-
baseurl::String = "127.0.0.1", http_port::Int = "8081",
132+
baseurl::String = "127.0.0.1", http_port::Int = 8081,
134133
verbose = false, singleton = true,
135134
websocket_route = "/webio_websocket/",
136135
logging_io = devnull,
137136
server_kw_args...
138137
)
138+
# TODO test if actually still running, otherwise restart even if singleton
139139
if !singleton || !isassigned(singleton_instance)
140140
handler = HTTP.HandlerFunction() do req
141141
serve_assets(req, default_response)
@@ -153,3 +153,32 @@ function WebIOServer(
153153
end
154154
return singleton_instance[]
155155
end
156+
157+
const webio_server_config = Ref{typeof((url = "", http_port = 0, ws_url = ""))}()
158+
159+
function global_server_config()
160+
if !isassigned(webio_server_config)
161+
webio_server_config[] = (
162+
url = get(ENV, "WEBIO_SERVER_HOST_URL", "127.0.0.1"),
163+
http_port = parse(Int, get(ENV, "WEBIO_HTTP_PORT", "8081")),
164+
ws_url = get(ENV, "WEBIO_WEBSOCKT_URL", url * ":" * http_port * "/webio_websocket/")
165+
)
166+
end
167+
webio_server_config[]
168+
end
169+
170+
function Base.show(io::IO, ::MIME"application/webio", app::Union{Scope, Node})
171+
# Make sure we run a server
172+
c = global_server_config()
173+
WebIOServer(baseurl = c.url, http_port = c.http_port)
174+
175+
webio_script = wio_asseturl("/webio/dist/bundle.js")
176+
ws_script = wio_asseturl("/providers/websocket_connection.js")
177+
178+
println(io, "<script> var websocket_url = $(repr(c.ws_url)) </script>")
179+
println(io, "<script src=$(repr(webio_script))></script>")
180+
println(io, "<script src=$(repr(ws_script)) ></script>")
181+
tohtml(io, app)
182+
183+
return
184+
end

0 commit comments

Comments
 (0)