Skip to content

Commit

Permalink
Merge pull request #224 from JuliaGizmos/sd-221
Browse files Browse the repository at this point in the history
remove wrong normpath, allow to customize bundle url
  • Loading branch information
SimonDanisch authored Nov 8, 2018
2 parents 7f17447 + c1319fd commit 116956c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 53 deletions.
13 changes: 8 additions & 5 deletions src/providers/generic_http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function WebIOServer(
return singleton_instance[]
end

const webio_server_config = Ref{typeof((url = "", http_port = 0, ws_url = ""))}()
const webio_server_config = Ref{typeof((url = "", bundle_url = "", http_port = 0, ws_url = ""))}()

"""
Fetches the global configuration for our http + websocket server from environment
Expand All @@ -118,8 +118,12 @@ function global_server_config()
http_port = parse(Int, get(ENV, "WEBIO_HTTP_PORT", "8081"))
ws_default = string("ws://", url, ":", http_port, "/webio_websocket/")
ws_url = get(ENV, "WEBIO_WEBSOCKT_URL", ws_default)
webio_server_config[] = (url = url, http_port = http_port, ws_url = ws_url)

# make it possible, to e.g. host the bundle online
bundle_url = get(ENV, "WEBIO_BUNDLE_URL", string(WebIO.baseurl[], bundle_key))
webio_server_config[] = (
url = url, bundle_url = bundle_url,
http_port = http_port, ws_url = ws_url
)
end
webio_server_config[]
end
Expand All @@ -142,9 +146,8 @@ end
function Base.show(io::IO, m::WEBIO_APPLICATION_MIME, app::Application)
c = global_server_config()
WebIOServer(routing_callback[], baseurl = c.url, http_port = c.http_port)
bundle_url = normpath("$(WebIO.baseurl[])/$(bundle_key)")
println(io, "<script>window._webIOWebSocketURL = $(repr(c.ws_url));</script>")
println(io, "<script src=$(repr(bundle_url))></script>")
println(io, "<script src=$(repr(c.bundle_url))></script>")
show(io, "text/html", app)
return
end
49 changes: 1 addition & 48 deletions test/http-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,6 @@ using Test
@test occursin("_webIOWebSocketURL = ", output)
@test occursin("ws://127.0.0.1:8081/webio_websocket/", output)
@test occursin("""hello, world""", output)
@test WebIO.webio_server_config[] == (url = "127.0.0.1", http_port = 8081, ws_url = "ws://127.0.0.1:8081/webio_websocket/")
@test WebIO.webio_server_config[] == (url = "127.0.0.1", bundle_url = WebIO.bundle_key, http_port = 8081, ws_url = "ws://127.0.0.1:8081/webio_websocket/")
@test isassigned(WebIO.singleton_instance)
end


using WebSockets, WebIO

app = Ref{Any}(node(:div, "hi"))
function serve_app(req)
if req.target == "/"
return sprint() do io
print(io,
"""
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
"""
)
show(io, WebIO.WEBIO_APPLICATION_MIME(), app[])
print(io,
"""
</body>
</html>
"""
)
end
else
return missing
end
end
server = WebIO.WebIOServer(serve_app, logger = stdout, verbose = true)
server.serve_task

w = Scope()

obs = Observable(w, "rand-value", 0.0)

on(obs) do x
println("JS sent $x")
end

app[] = w(
dom"button"(
"generate random",
events=Dict("click" => js"""function() { _webIOScope.setObservableValue('rand-value', Math.random()); }"""),
),
);

0 comments on commit 116956c

Please sign in to comment.