allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kentontay...@apache.org
Subject allura git commit: Make debug pages and post permalinks work correctly when behind a proxy (like docker)
Date Fri, 20 Apr 2018 14:32:58 GMT
Repository: allura
Updated Branches:
  refs/heads/master dff43b269 -> d55220204


Make debug pages and post permalinks work correctly when behind a proxy (like docker)


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

Branch: refs/heads/master
Commit: d55220204afac1daf646b5b538ab95ca18203b2f
Parents: dff43b2
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Feb 22 11:59:36 2018 -0500
Committer: Kenton Taylor <ktaylor@slashdotmedia.com>
Committed: Fri Apr 20 14:18:14 2018 +0000

----------------------------------------------------------------------
 Allura/allura/config/middleware.py               |  6 ++++--
 Allura/allura/lib/custom_middleware.py           | 19 +++++++++++++++++++
 Allura/allura/templates/widgets/post_widget.html |  8 +++-----
 Allura/docs/getting_started/installation.rst     | 13 +++++++++++++
 4 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/d5522020/Allura/allura/config/middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index a7356e2..99f9329 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -58,6 +58,7 @@ from allura.lib.custom_middleware import CSRFMiddleware
 from allura.lib.custom_middleware import CORSMiddleware
 from allura.lib.custom_middleware import LoginRedirectMiddleware
 from allura.lib.custom_middleware import RememberLoginMiddleware
+from allura.lib.custom_middleware import SetRequestHostFromConfig
 from allura.lib import helpers as h
 
 __all__ = ['make_app']
@@ -177,8 +178,9 @@ def _make_core_app(root, global_conf, full_stack=True, **app_conf):
         # Converts exceptions to HTTP errors, shows traceback in debug mode
         # don't use TG footer with extra CSS & images that take time to load
         tg.error.footer_html = '<!-- %s %s -->'
-        app = tg.error.ErrorHandler(
-            app, global_conf, **config['pylons.errorware'])
+        app = tg.error.ErrorHandler(app, global_conf, **config['pylons.errorware'])
+
+        app = SetRequestHostFromConfig(app, config)
 
         # Redirect some status codes to /error/document
         if asbool(config['debug']):

http://git-wip-us.apache.org/repos/asf/allura/blob/d5522020/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index b510d8f..e558080 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -260,6 +260,25 @@ class SSLMiddleware(object):
         return resp(environ, start_response)
 
 
+class SetRequestHostFromConfig(object):
+    """
+    Set request properties for host and port, based on the 'base_url' config setting.
+    This permits code to use request.host etc to construct URLs correctly, even when behind
a proxy, like in docker
+    """
+    def __init__(self, app, config):
+        self.app = app
+        self.config = config
+
+    def __call__(self, environ, start_response):
+        environ['HTTP_HOST'] = tg.config['base_url'].split('://')[1]
+        # setting environ['wsgi.url_scheme'] would make some links use the right http/https
scheme, but is not safe
+        # since the app may accept both http and https inbound requests, and many places
in code need to check that
+        # potentially could set wsgi.url_scheme based on 'HTTP_X_FORWARDED_SSL' == 'on' and/or
+        #   'HTTP_X_FORWARDED_PROTO' == 'https'
+        resp = self.app
+        return resp(environ, start_response)
+
+
 class AlluraTimerMiddleware(TimerMiddleware):
 
     def timers(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/d5522020/Allura/allura/templates/widgets/post_widget.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/post_widget.html b/Allura/allura/templates/widgets/post_widget.html
index bb97234..aae71e1 100644
--- a/Allura/allura/templates/widgets/post_widget.html
+++ b/Allura/allura/templates/widgets/post_widget.html
@@ -19,13 +19,11 @@
 {% import 'allura:templates/jinja_master/lib.html' as lib with context %}
 
 {% if page == 0 %}
-  {% set params = None %}
+  {% set params = '' %}
 {% else %}
-  {% set params = dict(page=page, limit=limit) %}
+  {% set params = '?page={}&limit={}'.format(page, limit) %}
 {% endif %}
-{% set shortlink_url = tg.url(
-  request.scheme + '://' + request.host + url.current(), params)
-  + '#' + value.slug %}
+{% set shortlink_url = h.absurl(url.current() + params + '#' + value.slug) %}
 
 <div>
   <div id="{{value.slug}}" class="discussion-post{%if value.is_meta %} meta_post{% endif
%}">

http://git-wip-us.apache.org/repos/asf/allura/blob/d5522020/Allura/docs/getting_started/installation.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/installation.rst b/Allura/docs/getting_started/installation.rst
index 4df2994..92021a3 100644
--- a/Allura/docs/getting_started/installation.rst
+++ b/Allura/docs/getting_started/installation.rst
@@ -44,6 +44,19 @@ you're in a directory that Virtual Box shares through to the VM (by default,
any
    Then run :code:`export COMPOSE_FILE=docker-compose-prod.yml` and continue running the
following commands.
    This will give you HTTPS, settings for better performance and no debugging, and only expose
necessary ports.
 
+.. note::
+
+   If you are running Docker inside a VM (or access it by a different hostname for any reason),
edit
+   :file:`Allura/docker-dev.ini` and add these lines after :code:`[app:main]`
+
+   .. code-block:: ini
+
+      domain = hostname-or-ip
+      base_url = http://hostname-or-ip:8080
+
+   Replace :kbd:`hostname-or-ip` with the actual hostname or external IP address.  If you
change this setting later,
+   just run :kbd:`docker-compose restart web`
+
 
 Run the following commands in your allura directory:
 


Mime
View raw message