Skip to content

Commit d5658ed

Browse files
committed
allow requesting the html file through the api itself
1 parent b2adca9 commit d5658ed

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

‎examples/websocket.rb‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
require'goliath'
55
require'goliath/websocket'
6+
require'goliath/rack/templates'
67

7-
require'yajl'
88
require'pp'
99

10-
classWebsocket < Goliath::WebSocket
10+
classWebsocketEndPoint < Goliath::WebSocket
1111
defon_open(env)
1212
env.logger.info("WS OPEN")
1313
env['subscription']=env.channel.subscribe{ |m| env.stream_send(m)}
@@ -27,3 +27,19 @@ def on_error(env, error)
2727
env.logger.errorerror
2828
end
2929
end
30+
31+
classWSInfo < Goliath::API
32+
includeGoliath::Rack::Templates
33+
34+
defresponse(env)
35+
[200,{},erb(:index,:views=>Goliath::Application.root_path('ws'))]
36+
end
37+
end
38+
39+
classWebsocket < Goliath::API
40+
get'/'do
41+
runWSInfo.new
42+
end
43+
44+
map"/ws",WebsocketEndPoint
45+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
return;
1818
}
1919

20-
varws=newWebSocket("ws://localhost:9000/");
20+
varws=newWebSocket("ws://localhost:9000/ws");
2121
ws.onmessage=function(evt){$("#msg").append("<p>"+evt.data+"</p>");};
2222
ws.onclose=function(){debug("socket closed");};
2323
ws.onopen=function(){debug("connected...");};

0 commit comments

Comments
(0)