From 51cb99b71046181530a5f59144debdcbb306be3a Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 7 Nov 2018 14:45:16 +0100 Subject: [PATCH 1/3] remove wrong normpath, allow to customize bundle url --- src/providers/generic_http.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/providers/generic_http.jl b/src/providers/generic_http.jl index f82244a0..40856c46 100644 --- a/src/providers/generic_http.jl +++ b/src/providers/generic_http.jl @@ -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 @@ -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", "$(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 @@ -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, "") - println(io, "") + println(io, "") show(io, "text/html", app) return end From 22af36eb6feb27060d5c6a6d4be107df7d12c36c Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 7 Nov 2018 14:54:17 +0100 Subject: [PATCH 2/3] fix url --- src/providers/generic_http.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/generic_http.jl b/src/providers/generic_http.jl index 40856c46..4bd96b78 100644 --- a/src/providers/generic_http.jl +++ b/src/providers/generic_http.jl @@ -119,7 +119,7 @@ function global_server_config() ws_default = string("ws://", url, ":", http_port, "/webio_websocket/") ws_url = get(ENV, "WEBIO_WEBSOCKT_URL", ws_default) # make it possible, to e.g. host the bundle online - bundle_url = get(ENV, "WEBIO_BUNDLE_URL", "$(WebIO.baseurl[])/$(bundle_key)") + 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 From c1319fd161ff7b4852da6a2426a28e86e427d669 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 7 Nov 2018 15:22:27 +0100 Subject: [PATCH 3/3] fix tests --- test/http-tests.jl | 49 +--------------------------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/test/http-tests.jl b/test/http-tests.jl index 1c496457..bd6ea73f 100644 --- a/test/http-tests.jl +++ b/test/http-tests.jl @@ -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, - """ - - - - - - - """ - ) - show(io, WebIO.WEBIO_APPLICATION_MIME(), app[]) - print(io, - """ - - - """ - ) - 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()); }"""), - ), -);