You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2013/08/03 15:19:51 UTC

[2/2] git commit: updated refs/heads/1867-feature-plugins to 44a9dbc

load plugin Futon/Fauxon assets via /_plugins/<name>/


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/44a9dbc0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/44a9dbc0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/44a9dbc0

Branch: refs/heads/1867-feature-plugins
Commit: 44a9dbc0e1a35dcf19e610098432c934c63cfbc0
Parents: 140245d
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Aug 3 15:19:40 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sat Aug 3 15:19:40 2013 +0200

----------------------------------------------------------------------
 src/couch_plugins/src/couch_plugins_httpd.erl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/44a9dbc0/src/couch_plugins/src/couch_plugins_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins_httpd.erl b/src/couch_plugins/src/couch_plugins_httpd.erl
index d292ec6..83fd916 100644
--- a/src/couch_plugins/src/couch_plugins_httpd.erl
+++ b/src/couch_plugins/src/couch_plugins_httpd.erl
@@ -35,9 +35,23 @@ handle_req(#httpd{method='POST'}=Req) ->
         ?LOG_DEBUG("Plugin Spec: ~p", [PluginSpec]),
         couch_httpd:send_error(Req, {bad_request, Error})
     end;
+% handles /_plugins/<pluginname>/<file>
+% serves <plugin_dir>/<pluginname>-<pluginversion>-<otpversion>-<couchdbversion>/<file>
+handle_req(#httpd{method='GET',path_parts=[_, Name0 | Path0]}=Req) ->
+    Name = ?b2l(Name0),
+    Path = lists:map(fun binary_to_list/1, Path0),
+    OTPRelease = erlang:system_info(otp_release),
+    PluginVersion = couch_config:get("plugins", Name),
+    CouchDBVersion = couch_server:get_version(short),
+    FullName = string:join([Name, PluginVersion, OTPRelease, CouchDBVersion], "-"),
+    FullPath = filename:join([FullName, "priv", "www", string:join(Path, "/")]) ++ "/",
+    ?LOG_DEBUG("Serving ~p from ~p", [FullPath, plugin_dir()]),
+    couch_httpd:serve_file(Req, FullPath, plugin_dir());
 handle_req(Req) ->
     couch_httpd:send_method_not_allowed(Req, "POST").
 
+plugin_dir() ->
+  couch_config:get("couchdb", "plugin_dir").
 do_install(false, Plugin) ->
     couch_plugins:install(Plugin);
 do_install(true, Plugin) ->