Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cherrypy and relative path in WSGI app

running cherrypy with mod_wsgi on apache along with another php app. The cherrypy app is NOT mounted on root, but rather on something like 'localhost/apps/myapp' via WSGIScriptAlias in the apache config file.

In testapp.py, I have tried the following, and when I try to access localhost/apps/myapp in a browser:

app = cherrypy.tree.mount(MyApp(), '', 'settings.config') #FAILS WITH 404

and

app = cherrypy.tree.mount(MyApp(), '/apps/myapp', 'settings.config') # WORKS

The first case fails because cherrypy expects to be at the server root, instead of relative to where it is mounted via WSGI in apache.

Is there a preferred way to make cherrypy apps work relative to the path they are mounted in apache under WSGIScriptAlias?

Basically, I'll be running several cherrypy apps under several different paths, and would prefer if apache handled the dispatching (i.e. cherrypy just runs the app and doesn't worry about the relative path). This way i can avoid updating several different python files/config files everytime some of the relative paths on the server change.

Any suggestions?

btw, the cherrypy app is currently passed to the wsgi application as follows:

app = cherrypy.tree.mount(HelloWorld(), '', 'settings.config')
return app(environ, start_response)
like image 400
Bill Zimmerman Avatar asked Nov 09 '10 02:11

Bill Zimmerman


1 Answers

I am doing this, although this would require cherrypy to know the relative path:

class Dir: pass
root = Dir()
root.apps = Dir()
root.apps.myapp = MyApp()
cherrypy.tree.mount(root)

This allows me to structure the application in any way I need. I'm using nginx and not Apache, but I don't think it'll make any difference. Although it gets a bit wordy if you're using long paths with not much else in between.

cherrypy can support other dispatchers which might be better suited to what you're trying to do, or perhaps you need to write a custom one.

like image 186
Robie Basak Avatar answered Sep 29 '22 02:09

Robie Basak