Skip to content

Commit

Permalink
Improve Websocket example
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Feb 9, 2013
1 parent efbd913 commit 574c3d4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/websocket/priv/html_ws_client.html
Expand Up @@ -2,7 +2,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Websocket client</title> <title>Websocket client</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script src="/static/jquery.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">


var websocket; var websocket;
Expand Down
2 changes: 2 additions & 0 deletions examples/websocket/priv/static/jquery.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/websocket/rebar.config
@@ -1,4 +1,6 @@
{deps, [ {deps, [
{cowboy, ".*", {cowboy, ".*",
{git, "git://github.com/extend/cowboy.git", "master"}} {git, "git://github.com/extend/cowboy.git", "master"}},
{mimetypes, ".*",
{git, "git://github.com/spawngrid/mimetypes.git", "master"}}
]}. ]}.
4 changes: 3 additions & 1 deletion examples/websocket/src/toppage_handler.erl
Expand Up @@ -11,7 +11,9 @@ init(_Transport, Req, []) ->


handle(Req, State) -> handle(Req, State) ->
Html = get_html(), Html = get_html(),
{ok, Req2} = cowboy_req:reply(200, [], Html, Req), {ok, Req2} = cowboy_req:reply(200,
[{<<"content-type">>, <<"text/html">>}],
Html, Req),
{ok, Req2, State}. {ok, Req2, State}.


terminate(_Reason, _Req, _State) -> terminate(_Reason, _Req, _State) ->
Expand Down
6 changes: 5 additions & 1 deletion examples/websocket/src/websocket_app.erl
Expand Up @@ -13,7 +13,11 @@ start(_Type, _Args) ->
Dispatch = cowboy_router:compile([ Dispatch = cowboy_router:compile([
{'_', [ {'_', [
{"/", toppage_handler, []}, {"/", toppage_handler, []},
{"/websocket", ws_handler, []} {"/websocket", ws_handler, []},
{"/static/[...]", cowboy_static, [
{directory, {priv_dir, websocket, [<<"static">>]}},
{mimetypes, {fun mimetypes:path_to_mimes/2, default}}
]}
]} ]}
]), ]),
{ok, _} = cowboy:start_http(http, 100, [{port, 8080}], {ok, _} = cowboy:start_http(http, 100, [{port, 8080}],
Expand Down

0 comments on commit 574c3d4

Please sign in to comment.