Skip to content
Browse files

Added example app

  • Loading branch information...
1 parent a4632e9 commit b02983fbb07a73b1db5e513dbab06a4f968714d3 @maxlapshin maxlapshin committed Nov 4, 2011
View
4 Makefile
@@ -0,0 +1,4 @@
+
+
+all:
+ ./rebar compile
View
11 README.md
@@ -28,7 +28,7 @@ Add dispatch handler to cowboy:
```erlang
Dispatch = [
{'_', [
- {['...'], rack_handler, [{path,"../my_rails_app"}]}
+ {['...'], cowboy_rack_handler, [{path,"../my_rails_app"}]}
]}
],
cowboy:start_listener(http, 1,
@@ -39,6 +39,15 @@ cowboy:start_listener(http, 1,
Launch you application.
+If you don't understand, where to put these lines, than go to example-app subdirectory and run:
+
+```
+make
+run ~/Sites/my_rails_app
+```
+
+
+
Go to http://localhost:8080/ and you will see your started Rails app.
Handler should reload application if config.ru mtime is changed, so it should be compatible with capistrano deploy.
View
1 example-app/.gitignore
@@ -0,0 +1 @@
+ebin
View
1 example-app/Emakefile
@@ -0,0 +1 @@
+{"src/*", [debug_info, {outdir, "ebin"}, {i, "src"}]}.
View
7 example-app/Makefile
@@ -0,0 +1,7 @@
+
+
+all: getdeps
+ erl -make
+
+getdeps:
+ [ -d ../../cowboy ] || ../rebar get-deps
View
9 example-app/rebar.config
@@ -0,0 +1,9 @@
+%%-*- mode: erlang -*-
+{lib_dirs, ["deps"]}.
+{erl_opts, [debug_info, {i, "apps"}, warnings_as_errors]}.
+{require_otp_vsn, "R14"}.
+
+{deps, [
+ {cowboy, ".*", {git, "git://github.com/extend/cowboy.git", "master"}},
+ {rack, ".*", {git, "git://github.com/erlyvideo/rack.git", "master"}}
+]}.
View
16 example-app/run
@@ -0,0 +1,16 @@
+#!/usr/bin/env escript
+
+
+main([RackPath]) ->
+ Root = filename:dirname(escript:script_name()),
+ code:add_pathz(Root ++ "/ebin"),
+ code:add_pathz(Root ++ "/../ebin"),
+ [code:add_pathz(Path) || Path <- filelib:wildcard(Root ++ "/deps/*/ebin")],
+ [code:add_pathz(Path) || Path <- filelib:wildcard(Root ++ "/../../*/ebin")],
+ example_rack:start(RackPath),
+ io:get_line("Example Rack launched\n");
+
+
+main([]) ->
+ io:format("Usage: ~s ~~/Sites/my_rails_app~n", [escript:script_name()]),
+ ok.
View
12 example-app/src/example_rack.app.src
@@ -0,0 +1,12 @@
+{application, example_rack,
+ [
+ {description, ""},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, { example_rack, []}},
+ {env, []}
+ ]}.
View
26 example-app/src/example_rack.erl
@@ -0,0 +1,26 @@
+-module(example_rack).
+-author('Max Lapshin <max@maxidoors.ru>').
+
+-export([start/1, start/2, stop/1]).
+
+start(Path) ->
+ application:load(example_rack),
+ application:set_env(example_rack, path, Path),
+ application:start(cowboy),
+ application:start(example_rack).
+
+
+start(_, _) ->
+ {ok, Path} = application:get_env(example_rack, path),
+ Dispatch = [
+ {'_', [
+ {['...'], cowboy_rack_handler, [{path, Path}]}
+ ]}
+ ],
+ cowboy:start_listener(http, 1,
+ cowboy_tcp_transport, [{port, 8080}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+ ).
+
+stop(_) ->
+ ok.
View
BIN rebar
Binary file not shown.
View
2 src/rack_handler.erl → src/cowboy_rack_handler.erl
@@ -1,4 +1,4 @@
--module(rack_handler).
+-module(cowboy_rack_handler).
-author('Max Lapshin <max@maxidoors.ru>').
-export([init/3, handle/2, terminate/2]).

0 comments on commit b02983f

Please sign in to comment.
Something went wrong with that request. Please try again.