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 2019/05/21 09:01:15 UTC

[couchdb] 02/02: feat: move fauxton docroot config to OS env-vars for consistency

This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch fix/cleanup-config
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4e78cafcd22e5931dce6fc5df2a0f457098581e7
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Tue May 21 10:28:15 2019 +0200

    feat: move fauxton docroot config to OS env-vars for consistency
---
 dev/run                        | 14 ++++++++------
 rel/files/couchdb.in           |  1 +
 rel/overlay/etc/default.ini    |  1 -
 src/chttpd/src/chttpd_misc.erl |  9 +++++++--
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dev/run b/dev/run
index fec7d73..60e7d5c 100755
--- a/dev/run
+++ b/dev/run
@@ -249,11 +249,6 @@ def check_beams(ctx):
 
 @log("Prepare configuration files")
 def setup_configs(ctx):
-    if os.path.exists("src/fauxton/dist/release"):
-        fauxton_root = "src/fauxton/dist/release"
-    else:
-        fauxton_root = "share/www"
-
     for idx, node in enumerate(ctx["nodes"]):
         cluster_port, backend_port = get_ports(ctx, idx + ctx["node_number"])
         env = {
@@ -268,7 +263,6 @@ def setup_configs(ctx):
             "node_name": "-name %s@127.0.0.1" % node,
             "cluster_port": cluster_port,
             "backend_port": backend_port,
-            "fauxton_root": fauxton_root,
             "uuid": "fake_uuid_for_dev",
             "_default": "",
         }
@@ -530,6 +524,14 @@ def check_node_alive(url):
 
 def set_boot_env(ctx):
 
+    # fudge fauxton path
+    if os.path.exists("src/fauxton/dist/release"):
+        fauxton_root = "src/fauxton/dist/release"
+    else:
+        fauxton_root = "share/www"
+
+    os.environ["COUCHDB_FAUXTON_DOCROOT"] = fauxton_root
+
     # fudge default query server paths
     couchjs = os.path.join(ctx["rootdir"], "src", "couch", "priv", "couchjs")
     mainjs = os.path.join(ctx["rootdir"], "share", "server", "main.js")
diff --git a/rel/files/couchdb.in b/rel/files/couchdb.in
index aae179a..f441611 100755
--- a/rel/files/couchdb.in
+++ b/rel/files/couchdb.in
@@ -28,6 +28,7 @@ export PROGNAME=`echo $0 | sed 's/.*\///'`
 
 export COUCHDB_QUERY_SERVER_JAVASCRIPT="{{prefix}}/bin/couchjs {{prefix}}/share/server/main.js"
 export COUCHDB_QUERY_SERVER_COFFEESCRIPT="{{prefix}}/bin/couchjs {{prefix}}/share/server/main-coffee.js"
+export COUCHDB_FAUXTON_DOCROOT={{fauxton_root}}
 
 ARGS_FILE="${COUCHDB_ARGS_FILE:-$ROOTDIR/etc/vm.args}"
 SYSCONFIG_FILE="${COUCHDB_SYSCONFIG_FILE:-$ROOTDIR/releases/$APP_VSN/sys.config}"
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 2a92009..0d7ac6d 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -94,7 +94,6 @@ n=3
 port = {{cluster_port}}
 bind_address = 127.0.0.1
 backlog = 512
-docroot = {{fauxton_root}}
 socket_options = [{sndbuf, 262144}, {nodelay, true}]
 server_options = [{recbuf, undefined}]
 require_valid_user = false
diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl
index 5aa9aaf..819d782 100644
--- a/src/chttpd/src/chttpd_misc.erl
+++ b/src/chttpd/src/chttpd_misc.erl
@@ -63,7 +63,7 @@ handle_welcome_req(Req, _) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 handle_favicon_req(Req) ->
-    handle_favicon_req(Req, config:get("chttpd", "docroot")).
+    handle_favicon_req(Req, get_docroot()).
 
 handle_favicon_req(#httpd{method='GET'}=Req, DocumentRoot) ->
     {DateNow, TimeNow} = calendar:universal_time(),
@@ -80,7 +80,7 @@ handle_favicon_req(Req, _) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 handle_utils_dir_req(Req) ->
-    handle_utils_dir_req(Req, config:get("chttpd", "docroot")).
+    handle_utils_dir_req(Req, get_docroot()).
 
 handle_utils_dir_req(#httpd{method='GET'}=Req, DocumentRoot) ->
     "/" ++ UrlPath = chttpd:path(Req),
@@ -504,3 +504,8 @@ message_queues(Registered) ->
         {Type, Length} = process_info(whereis(Name), Type),
         {Name, Length}
     end, Registered).
+
+get_docroot() ->
+    % if the env var isn’t set, let’s not throw an error, but
+    % assume the current working dir is what we want
+    os:getenv("COUCHDB_FAUXTON_DOCROOT", "").