0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

Fix eventsource example

This commit is contained in:
Loïc Hoguin 2016-06-14 17:05:41 +02:00
parent 84fb85e2e4
commit 5003bae369
3 changed files with 29 additions and 5 deletions

View file

@ -17,9 +17,9 @@ start(_Type, _Args) ->
{"/", cowboy_static, {priv_file, eventsource, "index.html"}}
]}
]),
{ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [
{env, [{dispatch, Dispatch}]}
]),
{ok, _} = cowboy:start_clear(http, 100, [{port, 8080}], #{
env => #{dispatch => Dispatch}
}),
eventsource_sup:start_link().
stop(_State) ->

View file

@ -7,8 +7,9 @@
-export([info/3]).
init(Req, Opts) ->
Headers = [{<<"content-type">>, <<"text/event-stream">>}],
Req2 = cowboy_req:chunked_reply(200, Headers, Req),
Req2 = cowboy_req:chunked_reply(200, #{
<<"content-type">> => <<"text/event-stream">>
}, Req),
erlang:send_after(1000, self(), {message, "Tick"}),
{cowboy_loop, Req2, Opts, 5000}.