Advertisement
joshuaboshi

virtual host in cherrypy 3.2 / python 3

Jun 29th, 2011
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import cherrypy
  4. from cherrypy import expose
  5.  
  6. class Root(object):
  7.    
  8.     @expose
  9.     def index(self):
  10.         return "I am the root  vhost"
  11.     index.exposed = True
  12.  
  13. class Foo(object):
  14.    
  15.     @expose
  16.     def index(self):
  17.         return "I am testingdomain.com"
  18.     index.exposed = True
  19.  
  20. class Bar(object):
  21.    
  22.     @expose
  23.     def index(self):
  24.         return "I am testingdomain2.com."
  25.     index.exposed = True
  26.  
  27. def main():
  28.    
  29.     #cherrypy.config.update("conf.ini")
  30.    
  31.     cherrypy.config.update({'server.socket_host': 'rootdomain.com',
  32.             'server.socket_port': 80,
  33.     })
  34.    
  35.     conf = {
  36.         "/": {
  37.             "request.dispatch": cherrypy.dispatch.VirtualHost(
  38.             **{
  39.                 "testingdomain.com:8000": "/foo",
  40.                 "testingdomain2.com:8000": "/bar"
  41.             })
  42.         }
  43.     }
  44.    
  45.     root = Root()
  46.     root.foo = Foo()
  47.     root.bar = Bar()
  48.     cherrypy.tree.mount(root, "/", conf)
  49.    
  50.     #cherrypy.quickstart()
  51.     cherrypy.engine.start()
  52.     cherrypy.engine.block()
  53.    
  54. if __name__ == "__main__":
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement