Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions examples/cowboy_echo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@

-export([main/1]).

%% Cowboy callbacks
-export([init/3, handle/2, terminate/3]).


main(_) ->
Port = 8081,
ok = application:start(xmerl),
ok = application:start(sockjs),
ok = application:start(ranch),
ok = application:start(crypto),
ok = application:start(cowlib),
ok = application:start(cowboy),

SockjsState = sockjs_handler:init_state(
<<"/echo">>, fun service_echo/3, state, []),

VhostRoutes = [{<<"/echo/[...]">>, sockjs_cowboy_handler, SockjsState},
{'_', ?MODULE, []}],
{"/", cowboy_static, {file, "./examples/echo.html"}}],
Routes = [{'_', VhostRoutes}], % any vhost
Dispatch = cowboy_router:compile(Routes),

Expand All @@ -35,20 +32,6 @@ main(_) ->

%% --------------------------------------------------------------------------

init({_Any, http}, Req, []) ->
{ok, Req, []}.

handle(Req, State) ->
{ok, Data} = file:read_file("./examples/echo.html"),
{ok, Req1} = cowboy_req:reply(200, [{<<"Content-Type">>, "text/html"}],
Data, Req),
{ok, Req1, State}.

terminate(_Reason, _Req, _State) ->
ok.

%% --------------------------------------------------------------------------

service_echo(_Conn, init, state) -> {ok, state};
service_echo(Conn, {recv, Data}, state) -> Conn:send(Data);
service_echo(_Conn, {info, _Info}, state) -> {ok, state};
Expand Down
1 change: 1 addition & 0 deletions examples/cowboy_test_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ main(_) ->
ok = application:start(sockjs),
ok = application:start(ranch),
ok = application:start(crypto),
ok = application:start(cowlib),
ok = application:start(cowboy),

StateEcho = sockjs_handler:init_state(
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
]}.

{deps, [
{cowboy, "0.8.3",{git, "https://github.com/extend/cowboy.git", "0.8.3"}}
{cowboy, "0.9.0",{git, "https://github.com/extend/cowboy.git", "0.9.0"}}
]}.