diff options
author | Loïc Hoguin <[email protected]> | 2013-09-08 20:17:25 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-09-08 20:17:25 +0200 |
commit | 24a22fa657af8398c963889d0bf08a904c96ec8c (patch) | |
tree | 0f3e2b39c1e700dadbc7afde176fb1f6600e30e0 /examples/ssl_hello_world | |
parent | 1f8119ef311911c3bc4567a198abd0237db6710d (diff) | |
download | cowboy-24a22fa657af8398c963889d0bf08a904c96ec8c.tar.gz cowboy-24a22fa657af8398c963889d0bf08a904c96ec8c.tar.bz2 cowboy-24a22fa657af8398c963889d0bf08a904c96ec8c.zip |
Convert the SSL hello world example to a release
Diffstat (limited to 'examples/ssl_hello_world')
-rw-r--r-- | examples/ssl_hello_world/Makefile | 14 | ||||
-rw-r--r-- | examples/ssl_hello_world/README.md | 30 | ||||
-rw-r--r-- | examples/ssl_hello_world/rebar.config | 4 | ||||
-rw-r--r-- | examples/ssl_hello_world/relx.config | 2 | ||||
-rw-r--r-- | examples/ssl_hello_world/src/ssl_hello_world.app.src | 3 | ||||
-rw-r--r-- | examples/ssl_hello_world/src/ssl_hello_world.erl | 15 | ||||
-rw-r--r-- | examples/ssl_hello_world/src/ssl_hello_world_app.erl | 7 | ||||
-rw-r--r-- | examples/ssl_hello_world/src/toppage_handler.erl | 4 | ||||
-rwxr-xr-x | examples/ssl_hello_world/start.sh | 3 |
9 files changed, 42 insertions, 40 deletions
diff --git a/examples/ssl_hello_world/Makefile b/examples/ssl_hello_world/Makefile new file mode 100644 index 0000000..412b2b3 --- /dev/null +++ b/examples/ssl_hello_world/Makefile @@ -0,0 +1,14 @@ +PROJECT = ssl_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/ssl_hello_world/README.md b/examples/ssl_hello_world/README.md index 766ff59..02bf13a 100644 --- a/examples/ssl_hello_world/README.md +++ b/examples/ssl_hello_world/README.md @@ -1,23 +1,27 @@ -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/ssl_hello_world_example console ``` -Then point your browser to the indicated URL. You will need to temporarily -trust the root certificate authority in `priv/ssl/cowboy-ca.crt`. +Then point your browser at [http://localhost:8443](http://localhost:8443). +You will need to temporarily trust the root certificate authority, +which can also be found in `priv/ssl/cowboy-ca.crt`. -Example -------- +Example output +-------------- ``` bash $ curl --cacert priv/ssl/cowboy-ca.crt -i https://localhost:8443 diff --git a/examples/ssl_hello_world/rebar.config b/examples/ssl_hello_world/rebar.config deleted file mode 100644 index 6ad3062..0000000 --- a/examples/ssl_hello_world/rebar.config +++ /dev/null @@ -1,4 +0,0 @@ -{deps, [ - {cowboy, ".*", - {git, "git://github.com/extend/cowboy.git", "master"}} -]}. diff --git a/examples/ssl_hello_world/relx.config b/examples/ssl_hello_world/relx.config new file mode 100644 index 0000000..d40e07b --- /dev/null +++ b/examples/ssl_hello_world/relx.config @@ -0,0 +1,2 @@ +{release, {ssl_hello_world_example, "1"}, [ssl_hello_world]}. +{extended_start_script, true}. diff --git a/examples/ssl_hello_world/src/ssl_hello_world.app.src b/examples/ssl_hello_world/src/ssl_hello_world.app.src index 514da1c..d628b68 100644 --- a/examples/ssl_hello_world/src/ssl_hello_world.app.src +++ b/examples/ssl_hello_world/src/ssl_hello_world.app.src @@ -8,7 +8,8 @@ {applications, [ kernel, stdlib, - cowboy + cowboy, + ssl ]}, {mod, {ssl_hello_world_app, []}}, {env, []} diff --git a/examples/ssl_hello_world/src/ssl_hello_world.erl b/examples/ssl_hello_world/src/ssl_hello_world.erl deleted file mode 100644 index 83c250e..0000000 --- a/examples/ssl_hello_world/src/ssl_hello_world.erl +++ /dev/null @@ -1,15 +0,0 @@ -%% Feel free to use, reuse and abuse the code in this file. - --module(ssl_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(ssl_hello_world). diff --git a/examples/ssl_hello_world/src/ssl_hello_world_app.erl b/examples/ssl_hello_world/src/ssl_hello_world_app.erl index ae8f0cf..3e53818 100644 --- a/examples/ssl_hello_world/src/ssl_hello_world_app.erl +++ b/examples/ssl_hello_world/src/ssl_hello_world_app.erl @@ -16,11 +16,12 @@ start(_Type, _Args) -> {"/", toppage_handler, []} ]} ]), + PrivDir = code:priv_dir(ssl_hello_world), {ok, _} = cowboy:start_https(https, 100, [ {port, 8443}, - {cacertfile, "priv/ssl/cowboy-ca.crt"}, - {certfile, "priv/ssl/server.crt"}, - {keyfile, "priv/ssl/server.key"} + {cacertfile, PrivDir ++ "/ssl/cowboy-ca.crt"}, + {certfile, PrivDir ++ "/ssl/server.crt"}, + {keyfile, PrivDir ++ "/ssl/server.key"} ], [{env, [{dispatch, Dispatch}]}]), ssl_hello_world_sup:start_link(). diff --git a/examples/ssl_hello_world/src/toppage_handler.erl b/examples/ssl_hello_world/src/toppage_handler.erl index 4124b5a..f0fa806 100644 --- a/examples/ssl_hello_world/src/toppage_handler.erl +++ b/examples/ssl_hello_world/src/toppage_handler.erl @@ -11,7 +11,9 @@ init(_Transport, 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/ssl_hello_world/start.sh b/examples/ssl_hello_world/start.sh deleted file mode 100755 index c8c7969..0000000 --- a/examples/ssl_hello_world/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -erl -pa ebin deps/*/ebin -s ssl_hello_world \ - -eval "io:format(\"Point your browser at https://localhost:8443~n\")." |