I've managed to get a proxy working using the following function. It's
based off a script I found here (https://gist.github.com/284772). The
original attempted solution using URL rewriting was abandoned. I expect it
to be slow clunky, potentially unsafe and incomplete. Please let me know if
anyone has a better solution.
def proxy():
import urllib2
# prevent Open Proxy abuse
allowedHosts = ['neomorph.salk.edu']
url = request.vars['url']
protocol, empty, host, folders = url.split("/", 3)
if host not in allowedHosts:
raise ValueError('This proxy does not allow you to access "%s"'%host
)
if protocol not in ('http:', 'https:'):
raise ValueError('Invalid protocol "%s"'%protocol)
method = request['wsgi'].environ['REQUEST_METHOD']
if method == "POST":
length = int(request['wsgi'].environ["CONTENT_LENGTH"])
headers = {"Content-Type": request['wsgi'].environ["CONTENT_TYPE"]}
body = request.body.read(length)
r = urllib2.Request(url, body, headers)
y = urllib2.urlopen(r)
else:
url = '%s?%s'%(url, '&'.join('%s=%s'%(key, val) for key, val inrequest
.vars.iteritems() if key != 'url'))
y = urllib2.urlopen(url)
msg = y.read()
y.close()
return msg
On Friday, March 16, 2012 5:26:59 PM UTC+1, Liam wrote:
>
> Dear all,
>
> I'm attempting to integrate the genome viewer AnnoJ into my application.
> To allow visitors to view data provided by another service, I need to
> configure a reverse proxy. This is easy enough to do in Apache, but I've
> been having problems doing this in web2py. I've tried several variations
> using the routes.py file:
>
> routes_in = (
>
> (r'matapax/default/annoj/(http://neomorph\.salk\.edu/epigenome/fetchers/arabidopsis_thaliana\.php)',
>
> r'\1'),
>
> (r'matapax/default/annoj/(http://neomorph\.salk\.edu/epigenome/fetchers/models/tair9\.php)',
>
> r'\1')
> )
>
> 1. With/without raw string (r'')
> 2. With/without 'matapax/default' in front of the strings (my application
> is called matapax, controller is default and function is annoj)
>
> The url I'm trying to proxy for is: "http:/
> neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php"
> Example variables: "?_dc=1331908909967&action=syndicate" (this should work
> if typed directly into the web browser url).
>
> Hopefully that was a little clearer than mud. Does anybody have any clues
> how to get an AnnoJ instance up and running with gene models from the salk
> url?
>
> Yours Sincerely,
> Liam
>
> The function itself returns an empty dictionary at the moment. The view
> looks like the example "Creating an AnnoJ instance" shown below.
>
> Creating an AnnoJ instance: http://www.annoj.org/instances/create.shtml
> Configuring an AnnoJ instance:
> http://www.annoj.org/instances/configure.shtml
> AnnoJ reverse proxy for Apache: http://www.annoj.org/instances/proxy.shtml
>
> My AnnoJ configuration file:
> //The Anno-J configuration object
> AnnoJ.config = {
>
> //List of configurations for all tracks in the Anno-J instance
> tracks : [
>
> {
> id : 'models',
> name : 'Gene Models',
> type : 'ModelsTrack',
> path : 'Annotation models',
> data : 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/models/tair9.php',
> height : 80,
> showControls : true
> }
> ],
>
> //A list of tracks that will be active by default (use the ID of
> the track)
> active : [
> 'models'
> ],
>
> //Address of service that provides information about this genome
> genome : 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php',
>
> //Address of service that stores / loads user bookmarks
> bookmarks : 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php',
>
> //A list of stylesheets that a user can select between (optional)
> stylesheets : [],
>
> //The default 'view'. In this example, chr1, position 1, zoom
> ratio 20:1.
> location : {
> assembly : '1',
> position : 1,
> bases : 20,
> pixels : 1
> },
>
> //Site administrator contact details (optional)
> admin : {
> name : 'Liam Childs',
> email : '[email protected]',
> notes : 'Golm, Germany'
> }
> };
>