provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management tls-sprint
authorFlorent <florent@secondweb.fr>
Tue, 28 Apr 2009 13:28:37 +0200
branchtls-sprint
changeset 1520 b097057e629d
parent 1490 6b024694d493
child 1521 973c5f1dfad4
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
cwconfig.py
etwist/server.py
--- a/cwconfig.py	Mon Apr 27 19:33:34 2009 +0200
+++ b/cwconfig.py	Tue Apr 28 13:28:37 2009 +0200
@@ -184,6 +184,14 @@
           'help': 'web server root url',
           'group': 'main', 'inputlevel': 1,
           }),
+        ('use-request-subdomain',
+         {'type' : 'yn',
+          'default': None,
+          'help': ('if set, base-url subdomain is replaced by the request\'s '
+                   'host, to help managing sites with several subdomains in a '
+                   'single cubicweb instance'),
+          'group': 'main', 'inputlevel': 1,
+          }),
         ('mangle-emails',
          {'type' : 'yn',
           'default': False,
--- a/etwist/server.py	Mon Apr 27 19:33:34 2009 +0200
+++ b/etwist/server.py	Tue Apr 28 13:28:37 2009 +0200
@@ -10,6 +10,7 @@
 import select
 from time import mktime
 from datetime import date, timedelta
+from urlparse import urlsplit, urlunsplit
 
 from twisted.application import service, strports
 from twisted.internet import reactor, task, threads
@@ -167,6 +168,12 @@
         else:
             https = False
             baseurl = self.base_url
+        if self.config['use-request-subdomain']:
+            scheme, netloc, url, query, fragment = urlsplit(baseurl)
+            if '.' in netloc:
+                netloc = '.'.join(host.split('.')[:1] + netloc.split('.')[1:])
+            baseurl = urlunsplit((scheme, netloc, url, query, fragment))
+            self.warning('base_url is %s for this request', baseurl)
         req = CubicWebTwistedRequestAdapter(request, self.appli.vreg, https, baseurl)
         if req.authmode == 'http':
             # activate realm-based auth