@@ -0,0 +1,2 @@
+deps
+ebin
@@ -0,0 +1,4 @@
+all:
+ ./rebar get-deps
+ ./rebar compile
+ erl -pa ebin deps/*/ebin -s hello_world -noshell -detached
@@ -0,0 +1,12 @@
+{
+ "framework": "cowboy",
+ "tests": [{
+ "default": {
+ "setup_file": "setup_erlang",
+ "json_url": "/json",
+ "db_url": "/db",
+ "query_url": "/db?queries=",
+ "port": 8080,
+ "sort": 38
+ }}]
+}
@@ -0,0 +1,7 @@
+{deps,
+ [
+ {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.8.3"}}},
+ {jsx, ".*", {git, "http://github.com/talentdeficit/jsx.git", {tag, "v1.3.3"}}},
+ {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {branch, master}}},
+ {cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {tag, "0.8.2"}}}
+ ]}.
@@ -0,0 +1,21 @@
+
+import subprocess
+import sys
+import setup_util
+def start(args):
+# setup_util.replace_text("rails/config/database-ruby.yml", "host: .*", "host: " + args.database_host)
+ try:
+ subprocess.check_call("./rebar get-deps", shell=True, cwd="cowboy")
+ subprocess.check_call("./rebar compile", shell=True, cwd="cowboy")
+ subprocess.check_call("erl -pa ebin deps/*/ebin -s hello_world -noshell -detached", shell=True, cwd="cowboy")
+ return 0
+ except subprocess.CalledProcessError:
+ return 1
+def stop():
+ subprocess.check_call("killall beam", shell=True, cwd="/usr/bin")
@@ -0,0 +1,15 @@
+%% Feel free to use, reuse and abuse the code in this file.
+{application, hello_world, [
+ {description, "Cowboy Hello World example."},
+ {vsn, "1"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ cowboy
+ ]},
+ {mod, {hello_world_app, []}},
+ {env, []}
+]}.
@@ -0,0 +1,14 @@
+-module(hello_world).
+%% API.
+-export([start/0]).
+start() ->
+ ok = application:start(crypto),
+ ok = application:start(ranch),
+ ok = application:start(cowboy),
+ ok = application:start(hello_world).
@@ -0,0 +1,26 @@
+%% @private
+-module(hello_world_app).
+-behaviour(application).
+-export([start/2]).
+-export([stop/1]).
+start(_Type, _Args) ->
+ application:start(jiffy),
+ Dispatch = cowboy_router:compile([
+ {'_', [
+ {"/json", toppage_handler, []}
+ ]}
+ ]),
+ {ok, _} = cowboy:start_http(http, 200, [{port, 8080}], [
+ {env, [{dispatch, Dispatch}]}
+ hello_world_sup:start_link().
+stop(_State) ->
+ ok.
@@ -0,0 +1,23 @@
+-module(hello_world_sup).
+-behaviour(supervisor).
+-export([start_link/0]).
+%% supervisor.
+-export([init/1]).
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+init([]) ->
+ Procs = [],
+ {ok, {{one_for_one, 10, 10}, Procs}}.
@@ -0,0 +1,18 @@
+%% @doc Hello world handler.
+-module(toppage_handler).
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+init(_Transport, Req, []) ->
+ {ok, Req, undefined}.
+handle(Req, State) ->
+ {ok, Req2} = cowboy_req:reply(200, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode({[{<<"message">>, <<"Hello, World!">>}]}), Req),
+ {ok, Req2, State}.
+terminate(_Reason, _Req, _State) ->