Browse Source

Some improvements on cowboy.

Heinz N. Gies 12 years ago
parent
commit
febca8b85f

+ 3 - 0
cowboy/.gitignore

@@ -1,2 +1,5 @@
+erl_crash.dump
+__init__.py
 deps
 ebin
+*.deb

+ 1 - 0
cowboy/rebar.config

@@ -3,5 +3,6 @@
   {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}}},
+  {emysql, ".*", {git, "https://github.com/Eonblast/Emysql.git"}},
   {cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {tag, "0.8.2"}}}
  ]}.

+ 2 - 0
cowboy/setup_erlang.py

@@ -7,6 +7,8 @@ def start(args):
 #  setup_util.replace_text("rails/config/database-ruby.yml", "host: .*", "host: " + args.database_host)
   
   try:
+    subprocess.check_call("/usr/bin/curl -klO https://elearning.erlang-solutions.com/couchdb//rbingen_adapter//package_R16B_precise64_1361901944/esl-erlang_16.b-1~ubuntu~precise_amd64.deb", shell=True, cwd="cowboy")
+    subprocess.check_call("sudo /usr/bin/dpkg --install esl-erlang_16.b-1~ubuntu~precise_amd64.deb", shell=True, cwd="cowboy")
     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")

+ 9 - 2
cowboy/src/hello_world_app.erl

@@ -11,13 +11,20 @@
 %% API.
 
 start(_Type, _Args) ->
+        crypto:start(),
+        application:start(emysql),
         application:start(jiffy),
+        emysql:add_pool(test_pool, 5,
+          "benchmarkdbuser", "benchmarkdbpass", "localhost", 3306,
+          "hello_world", utf8),
+	emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
 	Dispatch = cowboy_router:compile([
 		{'_', [
-			{"/json", toppage_handler, []}
+			{"/json", json_handler, []},
+			{"/db", db_handler, []}
 		]}
 	]),
-	{ok, _} = cowboy:start_http(http, 200, [{port, 8080}], [
+	{ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [
 		{env, [{dispatch, Dispatch}]}
 	]),
 	hello_world_sup:start_link().

+ 1 - 1
cowboy/src/json_handler.erl

@@ -1,7 +1,7 @@
 %% Feel free to use, reuse and abuse the code in this file.
 
 %% @doc Hello world handler.
--module(toppage_handler).
+-module(json_handler).
 
 -export([init/3]).
 -export([handle/2]).