Browse Source

Convert the EventSource example to a release

Loïc Hoguin 11 years ago
parent
commit
49acfce8b9

+ 14 - 0
examples/eventsource/Makefile

@@ -0,0 +1,14 @@
+PROJECT = eventsource
+
+DEPS = cowboy
+dep_cowboy = pkg://cowboy master
+
+.PHONY: release clean-release
+
+release: clean-release all
+	relx
+
+clean-release:
+	rm -rf _rel
+
+include ../../erlang.mk

+ 13 - 15
examples/eventsource/README.md

@@ -1,22 +1,20 @@
-Cowboy EventSource
-==================
+EventSource example
+===================
 
-To compile this example you need rebar in your PATH.
+To try this example, you need GNU `make`, `git` and
+[relx](https://github.com/erlware/relx) in your PATH.
 
-Type the following command:
-```
-$ rebar get-deps compile
-```
+To build the example, run the following command:
 
-You can then start the Erlang node with the following command:
-```
-./start.sh
+``` bash
+$ make
 ```
 
-Uses Cowboy's loop functionality to continuously send events to the browser.
+To start the release in the foreground:
 
-Example
--------
+``` bash
+$ ./_rel/bin/eventsource_example console
+```
 
-Point your browser to http://localhost:8080 to see EventSource in action with
-any modern browser (not IE).
+Then point your EventSource capable browser at
+[http://localhost:8080](http://localhost:8080).

+ 0 - 6
examples/eventsource/rebar.config

@@ -1,6 +0,0 @@
-{deps, [
-	{cowboy, ".*",
-		{git, "git://github.com/extend/cowboy.git", "master"}},
-	{mimetypes, ".*",
-		{git, "git://github.com/spawngrid/mimetypes.git", "master"}}
-]}.

+ 2 - 0
examples/eventsource/relx.config

@@ -0,0 +1,2 @@
+{release, {eventsource_example, "1"}, [eventsource]}.
+{extended_start_script, true}.

+ 0 - 15
examples/eventsource/src/eventsource.erl

@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(eventsource).
-
-%% API.
--export([start/0]).
-
-%% API.
-
-start() ->
-	ok = application:start(crypto),
-	ok = application:start(cowlib),
-	ok = application:start(ranch),
-	ok = application:start(cowboy),
-	ok = application:start(eventsource).

+ 1 - 1
examples/eventsource/src/eventsource_app.erl

@@ -17,7 +17,7 @@ start(_Type, _Args) ->
 			{"/", cowboy_static, [
 				{directory, {priv_dir, eventsource, []}},
 				{file, <<"index.html">>},
-				{mimetypes, {fun mimetypes:path_to_mimes/2, default}}
+				{mimetypes, [{<<".html">>, [<<"text/html">>]}]}
 			]}
 		]}
 	]),

+ 0 - 3
examples/eventsource/start.sh

@@ -1,3 +0,0 @@
-#!/bin/sh
-erl -pa ebin deps/*/ebin -s eventsource \
-	-eval "io:format(\"Point your browser at http://localhost:8080/~n\")."