Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added in SSL example

  • Loading branch information...
commit 32ea0f3afbb176edfbb0cf42f25dddadb2f4b0ce 1 parent 23f0218
@robertmeta authored
View
30 README.md
@@ -1,23 +1,33 @@
Quickstart
===============================================================================
-* If you already have *make*, *rebar* and *git* in your path
- * make && ./startit.sh
- * run whatever server you want by starting it example -> helloworld:start()
-
-Notes
-===============================================================================
-Many of these examples will have vast amounts of duplication in them, this is
-because each one is designed to be viewed and runnable in a bubble with the only
-external dependency being cowboy.
+* If you already have *make*, *rebar* and *git* in your path (even on windows)
+ * make && ./startit
+ * run whatever app you want by starting it -> helloworld:start()
+ * check it out at http://localhost:8080
+* *NOTE:* Apps all run on :8080 (even SSL) -- and must be run one by one
What is this?
===============================================================================
-This is a simple project to show many examples of using the Erlang Cowboy
+This is a simple project to show some examples of using the Erlang Cowboy
"Small, fast, modular HTTP server and socket acceptor pool". The first
order of business was to port all the amazing misultin examples over to
cowboy. Part of my motivation for doing this was the misultin end of
life.
+What isn't this?
+===============================================================================
+This isn't documentation, or intended as any sort of documentation replacement
+this is just a small set of working example you can run locally and quickly.
+
+Too complicated?
+===============================================================================
+I did my best to keep it simple while following the OTP structure. If you are
+un-familiar with OTP some of the examples might seem overly wordy. I am not
+going to worry too much about that and just label it "bonus learning"!
+
+Each application was designed as an island able to be run completely seperate
+from the other applications (but obviously still has dependancies on cowboy).
+
Links
===============================================================================
* Cowboy -> https://github.com/extend/cowboy
View
8 apps/hello_world/src/hello_world.erl
@@ -1,15 +1,19 @@
-module(hello_world).
--export([start/0, stop/0]).
+-export([start/0, start/2, stop/0]).
start() ->
application:start(cowboy),
+ application:start(hello_world).
+
+start(_Type, _Args) ->
Dispatch = [
{'_', [{'_', hello_world_handler, []}]}
],
- cowboy:start_listener(my_http_listener, 3,
+ cowboy:start_listener(my_http_listener, 1,
cowboy_tcp_transport, [{port, 8080}],
cowboy_http_protocol, [{dispatch, Dispatch}]
).
stop() ->
+ application:stop(hello_world),
application:stop(cowboy).
View
13 apps/hello_world_ssl/priv/ssl/cert.pem
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIICBTCCAW4CCQCAOFSQ0jrIEjANBgkqhkiG9w0BAQUFADBHMQswCQYDVQQGEwJG
+UjETMBEGA1UECAwKU29tZS1TdGF0ZTEPMA0GA1UECgwGQ293Ym95MRIwEAYDVQQD
+DAlsb2NhbGhvc3QwHhcNMTEwNTIyMTEwMTA2WhcNMTIwNTIxMTEwMTA2WjBHMQsw
+CQYDVQQGEwJGUjETMBEGA1UECAwKU29tZS1TdGF0ZTEPMA0GA1UECgwGQ293Ym95
+MRIwEAYDVQQDDAlsb2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
+ALKFViVePRPfm1gwJTMoTWOXEKH0RXkU15jamIpZ1b/651Amh8BeWSYgZ9wwnLeP
+m9XvRHDweC6SfbV/V1z3AzSKJGeuMwDNXZqF8AM73x9IkzvuEstTlHumY38q/vdb
+3sLBluOZ5tp2ACIUy8ry3UYmL20Z+7nlFFjI+joYMiaXAgMBAAEwDQYJKoZIhvcN
+AQEFBQADgYEARnqt9W2ZBxq6/kw66A5XK/DvusBz7Kc580AWfjXySRRrBeyp+oJn
+HuDCJfp5AsqiO265wVhzASBPvwKi25AKyCmPknWWFeUDujViWVglVU3t4Cz2adTe
+yxUbdytt8jd4e4Yn6jYf7IeRPFUSJtLXLBsarBQ7Fd3vyFSN9omxsEA=
+-----END CERTIFICATE-----
View
18 apps/hello_world_ssl/priv/ssl/key.pem
@@ -0,0 +1,18 @@
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: DES-EDE3-CBC,388902A98E10B962
+
+3eSNCY9OwPtCwRFJUHTCuEn4ktjoqWuFatCtbL7VQlvfC9yAr1qlxya6szjERPF4
+yV02CMyYQfdMLaAHqeWSwwC3lxdF0cVsQv+kvyneyDt3oRggvcnRrKsgAfFAuWns
+mD4vQQNxbnhB0s4c/vAq7itrItsHpnpYxPmoaNwEod3sWDLLOrEgS6kNrl/28nyJ
+w3cXK8B7LrbgQ18g/XHQ3xeBjrZ8WcwtZBgcybjUUKs66p4zIWlM6iJTe5K73OFT
+5odD3yxTn8cUTapGm7SgnB2EcbAs1O6Z2fGD3b3yJS0qLtRwJRr9cDS/ZRhegifG
+SMMDdwYYmp/EBBDnQMSDII5BJD25UPo51iWoXPPrnxFHU2Dc0fEjU3YS8P9gUTcq
+tJzsgMdgJpkaUhLh+VRLfuIXNnGmsgF33RZ7TjcgVKyZc1wxEBS7nl00BfuPl3Dl
+RHPfMX+5Fvypelgr511IsEdOTYe1oyK1Lwgsc2RSqtP3Rbo5ctIM0DkKp8f8R3cu
+nLB1eviQIYLEiFqfzqeUshHsNC3kwMdlj3cp9cbeBVpjXDbUvdNmkIe3D4CBXEEJ
+LjzBwCOegBW53g8g/Tf6PCw073t8d8p/1IojxTb66DEbzZuMIHlkH/O+uSR1uWje
+R27E7/trYM6G1heB2rb0Pu1OA0H191AyUrpjFeRR3bR9jtc+PVBk0R0oeR7y3ckj
+mSnrowDfewegMCwLYWIKFgRA+y+08lRrbRaqPgTiqg0WajTRBSj76fS2VDMCZXP1
+E9pKUTuv0uIiG5HNOS4M0LrOHWfOEZ4Ceu5Nj65wOvQ=
+-----END RSA PRIVATE KEY-----
View
14 apps/hello_world_ssl/src/hello_world_ssl.app.src
@@ -0,0 +1,14 @@
+{application, hello_world_ssl, [
+ {description, "Hello World SSL Example"},
+ {vsn, git},
+ {modules, []},
+ {registered, [hello_world_ssl_sup]},
+ {applications, [
+ kernel,
+ stdlib,
+ cowboy
+ ]},
+ {mod, {hello_world_ssl, []}},
+ {env, []}
+]}.
+
View
21 apps/hello_world_ssl/src/hello_world_ssl.erl
@@ -0,0 +1,21 @@
+-module(hello_world_ssl).
+-export([start/0, start/2, stop/0]).
+
+start() ->
+ application:start(cowboy),
+ application:start(hello_world_ssl).
+
+start(_Type, _Args) ->
+ Dispatch = [
+ {'_', [{'_', hello_world_ssl_handler, []}]}
+ ],
+ cowboy:start_listener(my_https_listener, 1,
+ cowboy_ssl_transport, [
+ {port, 8080}, {certfile, "priv/ssl/cert.pem"},
+ {keyfile, "priv/ssl/key.pem"}, {password, "cowboy"}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+ ).
+
+stop() ->
+ application:stop(hello_world_ssl),
+ application:stop(cowboy).
View
12 apps/hello_world_ssl/src/hello_world_ssl_handler.erl
@@ -0,0 +1,12 @@
+-module(hello_world_ssl_handler).
+-export([init/3, handle/2, terminate/2]).
+
+init({tcp, http}, Req, _Opts) ->
+ {ok, Req, undefined_state}.
+
+handle(Req, State) ->
+ {ok, Reply} = cowboy_http_req:reply(200, [], <<"Hello World!">>, Req),
+ {ok, Reply, State}.
+
+terminate(_Req, _State) ->
+ ok.
View
9 apps/hello_world_ssl/src/hello_world_ssl_sup.erl
@@ -0,0 +1,9 @@
+-module(hello_world_ssl_sup).
+-behaviour(supervisor).
+-export([init/1, start_link/0]).
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init([]) ->
+ {ok, {{one_for_one, 10, 10}, []}}.
View
3  rebar.config
@@ -1,5 +1,6 @@
{sub_dirs, [
- "apps/hello_world"
+ "apps/hello_world",
+ "apps/hello_world_ssl"
]}.
{require_otp_vsn, "R15"}.
View
4 startit
@@ -1,6 +1,6 @@
#!/bin/sh
erl \
- -pa deps/cowboy/ebin \
- -pa apps/hello_world/ebin \
+ -pa deps/*/ebin \
+ -pa apps/*/ebin \
-boot start_sasl
Please sign in to comment.
Something went wrong with that request. Please try again.