Skip to content

Commit

Permalink
Enable the localhost port of the web server to be configured
Browse files Browse the repository at this point in the history
This represents the port that the webserver is running on when
accessed from localhost.  This is used in the GDAL data source used to
access the tile mapping service through a self-referencing URL. It
needs to be set if port forwarding is used to expose the application
to an external web server on a non-standard port, which otherwise
results in an invalid `SERVER_PORT` server variable (the forwarded
port is used, rather than the actual local port).

Conflicts:
	docker/base/Dockerfile
  • Loading branch information
Homme Zwaagstra committed Dec 17, 2013
1 parent daf3783 commit 150ef33
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
10 changes: 10 additions & 0 deletions etc/portal.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
[DEFAULT]
email = [email protected]

; This represents the port that the webserver is running on when
; accessed from localhost. This is used in the GDAL data source used
; to access the tile mapping service through a self-referencing
; URL. It needs to be set if port forwarding is used to expose the
; application to an external web server on a non-standard port, which
; otherwise results in an invalid `SERVER_PORT` server variable (the
; forwarded port is used, rather than the actual local port).
;
;local_port = 80

[SMTP]
; Uncomment and edit the following options to cater for non default
; SMTP settings
Expand Down
22 changes: 10 additions & 12 deletions python/medin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,23 @@ def script_path(self):
return path_info

# code adapted from http://www.python.org/dev/peps/pep-0333/#url-reconstruction
def http_uri(self):
def http_uri(self, **kwargs):
url = self['wsgi.url_scheme']+'://'
server_port = kwargs.get('SERVER_PORT', self.get('SERVER_PORT', '80'))

try:
url += self['HTTP_HOST']
except KeyError:
url += self['SERVER_NAME']
url += self['SERVER_NAME']

if self['wsgi.url_scheme'] == 'https' and self['SERVER_PORT'] != '443':
url += ':' + self['SERVER_PORT']
elif self['SERVER_PORT'] != '80':
url += ':' + self['SERVER_PORT']
if self['wsgi.url_scheme'] == 'https' and server_port != '443':
url += ':' + server_port
elif server_port != '80':
url += ':' + server_port

return url

def script_uri(self):
def script_uri(self, **kwargs):
from urllib import quote

return self.http_uri() + quote(self.get('SCRIPT_NAME',''))
return self.http_uri(**kwargs) + quote(self.get('SCRIPT_NAME',''))

def resource_uri(self):
from urllib import quote
Expand Down Expand Up @@ -460,7 +458,7 @@ def wsgi_app():

# get an image representing the metadata bounds.
view = views.SOAPRequest(views.MetadataImage())
application.add('/{template}/catalogue/{gid:segment}/extent.png', GET=view)
application.add('/{template}/catalogue/{gid:segment}/extent.png', GET=config(view))

# download the metadata as CSV
view = views.SOAPRequest(views.MetadataCSV())
Expand Down
14 changes: 13 additions & 1 deletion python/medin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ def background_raster(template_lookup, environ):

import os.path
from mako.runtime import Context
from ConfigParser import NoOptionError

raster = 'background-wms.xml'
templatepath = os.path.join('config', raster)
Expand All @@ -1037,7 +1038,18 @@ def background_raster(template_lookup, environ):

# render the template to the file
fh = open(rasterpath, 'w')
ctx = Context(fh, resource_root=environ.script_uri())

# get the resource root, using a local HTTP port if set in the
# config.
config = environ['config']
try:
local_port = config.get('DEFAULT', 'local_port')
except NoOptionError:
resource_root = environ.script_uri()
else:
resource_root = environ.script_uri(SERVER_PORT=local_port)

ctx = Context(fh, resource_root=resource_root)
template.render_context(ctx)
fh.close()

Expand Down

0 comments on commit 150ef33

Please sign in to comment.