Permalink
Browse files

Initial Cowboy Support Stubs (help from @tuncer)

  • Loading branch information...
choptastic committed Jan 22, 2012
1 parent 130c626 commit 9b50e2d93316147eb0bbb555a33dec3a413ea2a5
View
@@ -6,6 +6,7 @@ help:
@echo "Usage: "
@echo " ./make {compile|clean}"
@echo
+ @echo " ./make {rel_cowboy|package_cowboy}"
@echo " ./make {rel_inets|package_inets}"
@echo " ./make {rel_mochiweb|package_mochiweb}"
@echo " ./make {rel_webmachine|package_webmachine}"
@@ -24,6 +25,20 @@ compile: get-deps
clean:
./rebar clean
+# COWBOY
+
+rel_cowboy: compile
+ @rm -rf rel/nitrogen
+ @rm -rf rel/reltool.config
+ @ln rel/reltool_cowboy.config rel/reltool.config
+ @(make rel_inner)
+ @echo Generated a self-contained Nitrogen project
+ @echo in 'rel/nitrogen', configured to run on Yaws.
+
+package_cowboy: rel_cowboy
+ mkdir -p ./builds
+ tar -C rel -c nitrogen | gzip > ./builds/nitrogen-${NITROGEN_VERSION}-yaws.tar.gz
+
# INETS
rel_inets: compile
View
@@ -2,7 +2,7 @@
Sincere thanks to all the people who have helped make Nitrogen great, including:
-* Rusty Klophaus (@rklophaus)
+* Rusty Klophaus (@rustyio)
* Chris Williams (@voodootikigod)
* Joel Reymont (@wagerlabs)
* Tom McNulty
@@ -21,11 +21,21 @@ Sincere thanks to all the people who have helped make Nitrogen great, including:
* Yurii Rashkovskii (@yrashk)
* Ville Koivula
* Manuel Durán Aguete
-* Jesse Gumm
+* Jesse Gumm (@jessegumm)
* Jan-Felix Wittmann
* Martin Sivak
* Jonas Ådahl
* Boris Faure
* Gregory Haskins
+* Dave Peticolas
+* Susan Potter
+* Ward Bekkar
+* Gleb Peregud
+* Lorant Kurthy
+* Andreas Hasselberg
+* Mattias Holmlund
+* Justin Kirby
+* Tuncer Ayaz
+* Loïc Hoguin (@lhoguin)
-Roughly sorted by date of contribution. Send your twitter handles to @rklophaus
+Roughly sorted by date of contribution. Send your twitter handles to @rustyio or @jessegumm
@@ -0,0 +1,25 @@
+{sub_dirs, [
+ "site",
+ "deps"
+]}.
+
+{require_otp_vsn, "R13B04|R14|R15"}.
+
+{cover_enabled, true}.
+
+{erl_opts, [debug_info, fail_on_warning]}.
+
+{deps_dir, ["lib"]}.
+
+{deps, [
+ {cowboy, "0.4", {git, "git://github.com/extend/cowboy",{tag, "HEAD"}}},
+
+ {nitrogen_core, "2.1.*", {git, "git://github.com/nitrogen/nitrogen_core", "HEAD"}},
+ {nprocreg, "0.2.*", {git, "git://github.com/nitrogen/nprocreg", "HEAD"}},
+ {simple_bridge, "1.2.*", {git, "git://github.com/nitrogen/simple_bridge", "HEAD"}},
+ {sync, "0.1.*", {git, "git://github.com/rustyio/sync.git", "HEAD"}}
+ %% {nitrogen_core, "2.1.*", {git, "git://github.com/nitrogen/nitrogen_core", {tag, "v2.1.0"}}},
+ %% {nprocreg, "0.2.*", {git, "git://github.com/nitrogen/nprocreg", {tag, "v0.2.0"}}},
+ %% {simple_bridge, "1.2.*", {git, "git://github.com/nitrogen/simple_bridge", {tag, "v1.2.0"}}},
+ %% {sync, "0.1.*", {git, "git://github.com/rustyio/sync.git", {tag, "v0.1.0"}}}
+]}.
@@ -0,0 +1,13 @@
+-module(nitrogen_app).
+-behaviour(application).
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ nitrogen_sup:start_link().
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,25 @@
+-module(nitrogen_cowboy).
+-behaviour(cowboy_http_handler).
+-export ([loop/1]).
+-include_lib("nitrogen_core/include/wf.hrl").
+
+-export([init/3, handle/2, terminate/2]).
+
+-record(state, {headers, body}).
+
+init({_Transport, http}, Req, Opts) ->
+ Headers = proplists:get_value(headers, Opts, []),
+ Body = proplists:get_value(body, Opts, "http_handler"),
+ {ok, Req, #state{headers=Headers, body=Body}}.
+
+handle(Req, State=#state{headers=Headers, body=Body}) ->
+ {ok, DocRoot} = application:get_env(cowboy, document_root),
+ RequestBridge = simple_bridge:make_request(cowboy_request_bridge,
+ {Req, DocRoot}),
+ ResponseBridge = simple_bridge:make_response(cowboy_response_bridge,
+ {Req, DocRoot}),
+ nitrogen:init_request(RequestBridge, ResponseBridge),
+ nitrogen:run().
+
+terminate(_Req, _State) ->
+ ok.
@@ -0,0 +1,45 @@
+%% -*- mode: nitrogen -*-
+-module(nitrogen_sup).
+-behaviour(supervisor).
+-export([
+ start_link/0,
+ init/1
+]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+ %% Start the Process Registry...
+ application:start(nprocreg),
+
+ %% Start Cowboy...
+ application:start(cowboy),
+ {ok, BindAddress} = application:get_env(cowboy, bind_address),
+ {ok, Port} = application:get_env(cowboy, port),
+ {ok, ServerName} = application:get_env(cowboy, server_name),
+ {ok, DocRoot} = application:get_env(cowboy, document_root),
+
+ io:format("Starting Cowboy Server (~s) on ~s:~p, root: '~s'~n",
+ [ServerName, BindAddress, Port, DocRoot]),
+
+ %% Start Cowboy...
+ Dispatch = [{'_', [{'_', nitrogen_cowboy, []}]}],
+ HttpOpts = [{max_keepalive, 50}, {dispatch, Dispatch}],
+ cowboy:start_listener(http, 100,
+ cowboy_tcp_transport, [{port, Port}],
+ cowboy_http_protocol, HttpOpts),
+
+ {ok, { {one_for_one, 5, 10}, []} }.
+
View
@@ -0,0 +1,40 @@
+{sys, [
+ {lib_dirs, ["../deps"]},
+ {rel, "nitrogen", "2.0.4",
+ [
+ kernel,
+ stdlib,
+ sasl,
+ inets,
+ crypto,
+ runtime_tools
+ ]},
+ {rel, "start_clean", "",
+ [
+ kernel,
+ stdlib
+ ]},
+ {boot_rel, "nitrogen"},
+ {profile, embedded},
+ {excl_sys_filters, [
+ "^bin/.*",
+ "^erts.*/bin/(dialyzer|typer)"
+ ]},
+ {app, sasl, [{incl_cond, include}]},
+ {app, eunit, [{incl_cond, include}]},
+ {incl_cond, include}
+]}.
+
+{overlay, [
+ %% Copy common files...
+ {copy, "./overlay/common/*"},
+ {copy, "./overlay/erts/*", "{{erts_vsn}}/bin"},
+ {copy, "../deps/nitrogen_core", "lib/nitrogen_core"},
+ {copy, "../deps/nitrogen_core/www", "site/static/nitrogen"},
+ {copy, "../deps/simple_bridge", "lib/simple_bridge"},
+ {copy, "../deps/nprocreg", "lib/nprocreg"},
+ {copy, "../deps/sync", "lib/sync"},
+
+ %% Copy Yaws files...
+ {copy, "overlay/cowboy/*"}
+]}.

0 comments on commit 9b50e2d

Please sign in to comment.