aboutsummaryrefslogtreecommitdiffstats
path: root/examples/static_world
diff options
context:
space:
mode:
Diffstat (limited to 'examples/static_world')
-rw-r--r--examples/static_world/Makefile14
-rw-r--r--examples/static_world/README.md52
-rw-r--r--examples/static_world/rebar.config6
-rw-r--r--examples/static_world/relx.config2
-rw-r--r--examples/static_world/src/static_world.erl15
-rw-r--r--examples/static_world/src/static_world_app.erl7
-rwxr-xr-xexamples/static_world/start.sh4
7 files changed, 43 insertions, 57 deletions
diff --git a/examples/static_world/Makefile b/examples/static_world/Makefile
new file mode 100644
index 0000000..4c7b600
--- /dev/null
+++ b/examples/static_world/Makefile
@@ -0,0 +1,14 @@
+PROJECT = static_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/static_world/README.md b/examples/static_world/README.md
index e947ebb..6d79948 100644
--- a/examples/static_world/README.md
+++ b/examples/static_world/README.md
@@ -1,49 +1,39 @@
-Cowboy Static File Handler
-==========================
+Static file handler 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
```
-Cowboy will serve all the files you put in the priv/ directory.
-You can replace the filename given in the example URL with the
-one of a file you added to this directory to receive that file.
+The example will serve all the files found in the `priv`
+directory. For example:
-Example
--------
+ * [Plain text file](http://localhost:8080/test.txt)
+ * [HTML5 video demo](http://localhost:8080/video.html)
-Show that the file is returned as an octet-stream
+Example output
+--------------
``` bash
$ curl -i http://localhost:8080/test.txt
HTTP/1.1 200 OK
connection: keep-alive
server: Cowboy
-date: Fri, 28 Sep 2012 04:19:40 GMT
+date: Mon, 09 Sep 2013 13:49:50 GMT
content-length: 52
-Content-Type: application/octet-stream
-Last-Modified: Fri, 28 Sep 2012 04:01:20 GMT
+content-type: text/plain
+last-modified: Fri, 18 Jan 2013 16:33:31 GMT
If you read this then the static file server works!
```
-
-Finally download and cat the file to verify
-
-``` bash
-$ curl -sLO http://localhost:8080/test.txt
-$ cat test.txt
-If you read this then the static file server works!
-```
-
-HTML5 Video Example
--------------------
-
-Open http://localhost:8080/video.html in your favorite browser.
diff --git a/examples/static_world/rebar.config b/examples/static_world/rebar.config
deleted file mode 100644
index eb6f194..0000000
--- a/examples/static_world/rebar.config
+++ /dev/null
@@ -1,6 +0,0 @@
-{deps, [
- {cowboy, ".*",
- {git, "git://github.com/extend/cowboy.git", "master"}},
- {mimetypes, ".*",
- {git, "git://github.com/spawngrid/mimetypes.git", "master"}}
-]}.
diff --git a/examples/static_world/relx.config b/examples/static_world/relx.config
new file mode 100644
index 0000000..a480902
--- /dev/null
+++ b/examples/static_world/relx.config
@@ -0,0 +1,2 @@
+{release, {static_world_example, "1"}, [static_world]}.
+{extended_start_script, true}.
diff --git a/examples/static_world/src/static_world.erl b/examples/static_world/src/static_world.erl
deleted file mode 100644
index 2bed337..0000000
--- a/examples/static_world/src/static_world.erl
+++ /dev/null
@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(static_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(static_world).
diff --git a/examples/static_world/src/static_world_app.erl b/examples/static_world/src/static_world_app.erl
index 6470f12..4cc0254 100644
--- a/examples/static_world/src/static_world_app.erl
+++ b/examples/static_world/src/static_world_app.erl
@@ -15,7 +15,12 @@ start(_Type, _Args) ->
{'_', [
{"/[...]", cowboy_static, [
{directory, {priv_dir, static_world, []}},
- {mimetypes, {fun mimetypes:path_to_mimes/2, default}}
+ {mimetypes, [
+ {<<".html">>, [<<"text/html">>]},
+ {<<".txt">>, [<<"text/plain">>]},
+ {<<".mp4">>, [<<"video/mp4">>]},
+ {<<".ogv">>, [<<"video/ogg">>]}
+ ]}
]}
]}
]),
diff --git a/examples/static_world/start.sh b/examples/static_world/start.sh
deleted file mode 100755
index 995f913..0000000
--- a/examples/static_world/start.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-erl -pa ebin deps/*/ebin -s static_world \
- -eval "io:format(\"Point your browser at http://localhost:8080/test.txt~n\")." \
- -eval "io:format(\"Point your browser at http://localhost:8080/video.html~n\")."