diff options
author | Loïc Hoguin <[email protected]> | 2013-09-09 16:21:53 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-09-09 16:21:53 +0200 |
commit | 834056402ac4a94baa1ab622f127dfdd84826bc3 (patch) | |
tree | 41df4341045ae9309e15dbd4f7812d18048e4e7b /examples/websocket/src | |
parent | 6a90d00ceee9c95d5d80190736e04f35bd04d8f4 (diff) | |
download | cowboy-834056402ac4a94baa1ab622f127dfdd84826bc3.tar.gz cowboy-834056402ac4a94baa1ab622f127dfdd84826bc3.tar.bz2 cowboy-834056402ac4a94baa1ab622f127dfdd84826bc3.zip |
Convert the websocket example to a release
Diffstat (limited to 'examples/websocket/src')
-rw-r--r-- | examples/websocket/src/toppage_handler.erl | 26 | ||||
-rw-r--r-- | examples/websocket/src/websocket.erl | 13 | ||||
-rw-r--r-- | examples/websocket/src/websocket_app.erl | 8 |
3 files changed, 6 insertions, 41 deletions
diff --git a/examples/websocket/src/toppage_handler.erl b/examples/websocket/src/toppage_handler.erl deleted file mode 100644 index b315a19..0000000 --- a/examples/websocket/src/toppage_handler.erl +++ /dev/null @@ -1,26 +0,0 @@ -%% Feel free to use, reuse and abuse the code in this file. - --module(toppage_handler). - --export([init/3]). --export([handle/2]). --export([terminate/3]). - -init(_Transport, Req, []) -> - {ok, Req, undefined}. - -handle(Req, State) -> - Html = get_html(), - {ok, Req2} = cowboy_req:reply(200, - [{<<"content-type">>, <<"text/html">>}], - Html, Req), - {ok, Req2, State}. - -terminate(_Reason, _Req, _State) -> - ok. - -get_html() -> - {ok, Cwd} = file:get_cwd(), - Filename =filename:join([Cwd, "priv", "html_ws_client.html"]), - {ok, Binary} = file:read_file(Filename), - Binary. diff --git a/examples/websocket/src/websocket.erl b/examples/websocket/src/websocket.erl deleted file mode 100644 index 23afe13..0000000 --- a/examples/websocket/src/websocket.erl +++ /dev/null @@ -1,13 +0,0 @@ -%% Feel free to use, reuse and abuse the code in this file. - --module(websocket). - -%% API. --export([start/0]). - -start() -> - ok = application:start(crypto), - ok = application:start(cowlib), - ok = application:start(ranch), - ok = application:start(cowboy), - ok = application:start(websocket). diff --git a/examples/websocket/src/websocket_app.erl b/examples/websocket/src/websocket_app.erl index 049c524..1b9a421 100644 --- a/examples/websocket/src/websocket_app.erl +++ b/examples/websocket/src/websocket_app.erl @@ -12,11 +12,15 @@ start(_Type, _Args) -> Dispatch = cowboy_router:compile([ {'_', [ - {"/", toppage_handler, []}, + {"/", cowboy_static, [ + {directory, {priv_dir, websocket, []}}, + {file, <<"index.html">>}, + {mimetypes, [{<<".html">>, [<<"text/html">>]}]} + ]}, {"/websocket", ws_handler, []}, {"/static/[...]", cowboy_static, [ {directory, {priv_dir, websocket, [<<"static">>]}}, - {mimetypes, {fun mimetypes:path_to_mimes/2, default}} + {mimetypes, [{<<".js">>, [<<"application/javascript">>]}]} ]} ]} ]), |