aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/hello_world/Makefile14
-rw-r--r--examples/hello_world/README.md28
-rw-r--r--examples/hello_world/rebar.config4
-rw-r--r--examples/hello_world/relx.config2
-rw-r--r--examples/hello_world/src/hello_world.erl15
-rw-r--r--examples/hello_world/src/toppage_handler.erl6
-rwxr-xr-xexamples/hello_world/start.sh3
7 files changed, 36 insertions, 36 deletions
diff --git a/examples/hello_world/Makefile b/examples/hello_world/Makefile
new file mode 100644
index 0000000..1e6ef79
--- /dev/null
+++ b/examples/hello_world/Makefile
@@ -0,0 +1,14 @@
+PROJECT = hello_world
+
+DEPS = cowboy
+dep_cowboy = pkg://cowboy master
+
+.PHONY: release clean-release
+
+release: clean-release all
+ relx
+
+clean-release:
+ rm -rf _rel
+
+include ../../erlang.mk
diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md
index dd3d948..84f3211 100644
--- a/examples/hello_world/README.md
+++ b/examples/hello_world/README.md
@@ -1,22 +1,25 @@
-Cowboy Hello World
-==================
+Hello world 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:
+``` bash
+$ make
```
-./start.sh
+
+To start the release in the foreground:
+
+``` bash
+$ ./_rel/bin/hello_world_example console
```
-Then point your browser to the indicated URL.
+Then point your browser at [http://localhost:8080](http://localhost:8080).
-Example
--------
+Example output
+--------------
``` bash
$ curl -i http://localhost:8080
@@ -25,6 +28,7 @@ connection: keep-alive
server: Cowboy
date: Fri, 28 Sep 2012 04:10:25 GMT
content-length: 12
+content-type: text/plain
Hello world!
```
diff --git a/examples/hello_world/rebar.config b/examples/hello_world/rebar.config
deleted file mode 100644
index 6ad3062..0000000
--- a/examples/hello_world/rebar.config
+++ /dev/null
@@ -1,4 +0,0 @@
-{deps, [
- {cowboy, ".*",
- {git, "git://github.com/extend/cowboy.git", "master"}}
-]}.
diff --git a/examples/hello_world/relx.config b/examples/hello_world/relx.config
new file mode 100644
index 0000000..b282ad9
--- /dev/null
+++ b/examples/hello_world/relx.config
@@ -0,0 +1,2 @@
+{release, {hello_world_example, "1"}, [hello_world]}.
+{extended_start_script, true}.
diff --git a/examples/hello_world/src/hello_world.erl b/examples/hello_world/src/hello_world.erl
deleted file mode 100644
index 5db51bf..0000000
--- a/examples/hello_world/src/hello_world.erl
+++ /dev/null
@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(hello_world).
-
-%% 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(hello_world).
diff --git a/examples/hello_world/src/toppage_handler.erl b/examples/hello_world/src/toppage_handler.erl
index 4124b5a..4839991 100644
--- a/examples/hello_world/src/toppage_handler.erl
+++ b/examples/hello_world/src/toppage_handler.erl
@@ -7,11 +7,13 @@
-export([handle/2]).
-export([terminate/3]).
-init(_Transport, Req, []) ->
+init(_Type, Req, []) ->
{ok, Req, undefined}.
handle(Req, State) ->
- {ok, Req2} = cowboy_req:reply(200, [], <<"Hello world!">>, Req),
+ {ok, Req2} = cowboy_req:reply(200, [
+ {<<"content-type">>, <<"text/plain">>}
+ ], <<"Hello world!">>, Req),
{ok, Req2, State}.
terminate(_Reason, _Req, _State) ->
diff --git a/examples/hello_world/start.sh b/examples/hello_world/start.sh
deleted file mode 100755
index b6d1b2d..0000000
--- a/examples/hello_world/start.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-erl -pa ebin deps/*/ebin -s hello_world \
- -eval "io:format(\"Point your browser at http://localhost:8080~n\")."