Skip to content

Commit e367eee

Browse files
SimonDanischshashi
authored andcommitted
update example
1 parent 8905c2d commit e367eee

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

src/providers/generic_http.jl

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,47 +79,53 @@ const singleton_instance = Ref{WebIOServer}()
7979
usage:
8080
8181
```example
82-
asset_port = 8081
83-
base_url = "127.0.0.1"
84-
websocket_port = 8000
85-
const app = Ref{Any}()
86-
87-
server = WebIOServer(
88-
baseurl = base_url, http_port = asset_port, ws_port = websocket_port,
89-
logging_io = stdout
90-
) do req
91-
req.target != "/" && return missing # don't do anything
92-
isassigned(app) || return "no app"
93-
ws_url = string("ws://", base_url, ':', websocket_port)
94-
webio_script = asseturl("/webio/dist/bundle.js")
95-
ws_script = asseturl("/providers/websocket_connection.js")
96-
return sprint() do io
97-
print(io, "
98-
<!doctype html>
99-
<html>
100-
<head>
101-
<meta charset="UTF-8">
102-
<script> var websocket_url = \$(repr(ws_url)) </script>
103-
<script src="\$webio_script"></script>
104-
<script src="\$ws_script"></script>
105-
</head>
106-
<body>
107-
")
108-
tohtml(io, app[])
109-
print(io, "
110-
</body>
111-
</html>
112-
")
82+
asset_port = 8081
83+
base_url = "127.0.0.1"
84+
const app = Ref{Any}()
85+
#WebIO.setbaseurl!(baseurl) # plus port!?
86+
server = WebIOServer(
87+
baseurl = base_url, http_port = asset_port, verbose = true
88+
) do req
89+
req.target != "/" && return missing # don't do anything
90+
isassigned(app) || return "no app"
91+
ws_url = string("ws://", base_url, ':', asset_port, "/webio_websocket/")
92+
webio_script = wio_asseturl("/webio/dist/bundle.js")
93+
ws_script = wio_asseturl("/providers/websocket_connection.js")
94+
return sprint() do io
95+
print(io, "
96+
<!doctype html>
97+
<html>
98+
<head>
99+
<meta charset="UTF-8">
100+
<script> var websocket_url = \$(repr(ws_url)) </script>
101+
<script src="\$webio_script"></script>
102+
<script src="\$ws_script"></script>
103+
</head>
104+
<body>
105+
")
106+
tohtml(io, app[])
107+
print(io, "
108+
</body>
109+
</html>
110+
")
111+
end
113112
end
114-
end
115113
116-
app[] = node(:div, "Hello, World",
117-
style = Dict(
118-
:backgroundColor => "black",
119-
:color => "white",
120-
:padding => "12px"
121-
)
122-
)
114+
w = Scope()
115+
116+
obs = Observable(w, "rand-value", 0.0)
117+
118+
on(obs) do x
119+
println("JS sent \$x")
120+
end
121+
122+
using JSExpr
123+
app[] = w(
124+
dom"button"(
125+
"generate random",
126+
events=Dict("click"=>@js () -> \$obs[] = Math.random()),
127+
),
128+
);
123129
```
124130
"""
125131
function WebIOServer(

0 commit comments

Comments
 (0)