Skip to content

Commit

Permalink
Convert the SSL hello world example to a release
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Sep 8, 2013
1 parent 1f8119e commit 24a22fa
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 40 deletions.
14 changes: 14 additions & 0 deletions 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
30 changes: 17 additions & 13 deletions 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
Expand Down
4 changes: 0 additions & 4 deletions examples/ssl_hello_world/rebar.config

This file was deleted.

2 changes: 2 additions & 0 deletions examples/ssl_hello_world/relx.config
@@ -0,0 +1,2 @@
{release, {ssl_hello_world_example, "1"}, [ssl_hello_world]}.
{extended_start_script, true}.
3 changes: 2 additions & 1 deletion examples/ssl_hello_world/src/ssl_hello_world.app.src
Expand Up @@ -8,7 +8,8 @@
{applications, [
kernel,
stdlib,
cowboy
cowboy,
ssl
]},
{mod, {ssl_hello_world_app, []}},
{env, []}
Expand Down
15 changes: 0 additions & 15 deletions examples/ssl_hello_world/src/ssl_hello_world.erl

This file was deleted.

7 changes: 4 additions & 3 deletions examples/ssl_hello_world/src/ssl_hello_world_app.erl
Expand Up @@ -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().

Expand Down
4 changes: 3 additions & 1 deletion examples/ssl_hello_world/src/toppage_handler.erl
Expand Up @@ -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) ->
Expand Down
3 changes: 0 additions & 3 deletions examples/ssl_hello_world/start.sh

This file was deleted.

0 comments on commit 24a22fa

Please sign in to comment.