From a8cf4dff133ecf4421eb585141f6fe347dbf9be2 Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Wed, 15 Jul 2015 08:37:47 -0700 Subject: [PATCH] Use dynamic http handlers We use dynamic http handlers for: - `_membership` - `_shards` --- src/mem3.app.src | 1 + src/mem3_httpd_handlers.erl | 23 +++++++++++++++++++++++ src/mem3_sup.erl | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/mem3_httpd_handlers.erl diff --git a/src/mem3.app.src b/src/mem3.app.src index 87eda0d..99a9eed 100644 --- a/src/mem3.app.src +++ b/src/mem3.app.src @@ -43,6 +43,7 @@ sasl, crypto, mochiweb, + couch_epi, couch, rexi, couch_log, diff --git a/src/mem3_httpd_handlers.erl b/src/mem3_httpd_handlers.erl new file mode 100644 index 0000000..d8e138c --- /dev/null +++ b/src/mem3_httpd_handlers.erl @@ -0,0 +1,23 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(mem3_httpd_handlers). + +-export([url_handler/1, db_handler/1, design_handler/1]). + +url_handler(<<"_membership">>) -> fun mem3_httpd:handle_membership_req/1; +url_handler(_) -> no_match. + +db_handler(<<"_shards">>) -> fun mem3_httpd:handle_shards_req/2; +db_handler(_) -> no_match. + +design_handler(_) -> no_match. diff --git a/src/mem3_sup.erl b/src/mem3_sup.erl index 6ff688b..915bee4 100644 --- a/src/mem3_sup.erl +++ b/src/mem3_sup.erl @@ -23,7 +23,8 @@ init(_Args) -> child(mem3_nodes), child(mem3_sync_nodes), % Order important? child(mem3_sync), - child(mem3_shards) + child(mem3_shards), + chttpd_handlers:provider(mem3, mem3_httpd_handlers) ], {ok, {{one_for_one,10,1}, Children}}.