Commits

Sylvain Hellegouarch committed 80604ea

multi apps

  • Participants
  • Parent commits 2f34ac0

Comments (0)

Files changed (1)

deployment/multi_apps/__init__.py

+# -*- coding: utf-8 -*-
+""" CherryPy can hold several applications in one given instance
+of the server.
+
+To do so use ``cherrypy.tree.mount`` which associates
+an instance of an application with a URL path segment.
+
+That path is the root point at which the application
+will be reachable.
+
+So if your app is mounted at /blog, requests to
+/forum will not reach anything. Only requests
+starting with /blog. 
+
+``cherrypy.tree.mount`` has the interesting
+property of sandboxing your applications
+one from the other.
+
+So for instance:
+
+    cherrypy.tree.mount(App1(), '/app1', {'/': {'tools.etags.on': True}})
+    cherrypy.tree.mount(App2(), '/app2', {'/': {'tools.etags.on': False}})
+    
+Both applications won't be aware of the other.
+This means that the provided configurations
+are per application.
+
+Note that configuration must be relative to
+root point where the apps are mounted.
+This is why we use the '/' configuration section
+since the configuration is applied to
+the application independantly from where
+it was mounted.
+"""
+import cherrypy
+
+class App1(object):
+    @cherrypy.expose
+    def index(self):
+        return "Hello world from app1"
+    
+class App2(object):
+    @cherrypy.expose
+    def index(self):
+        return "Hello world from app2"
+
+if __name__ == '__main__':
+    cherrypy.config.update({'server.socket_port': 8090})
+
+    cherrypy.tree.mount(App1(), '/app1', {'/': {'tools.etags.on': True}})
+    cherrypy.tree.mount(App2(), '/app2', {'/': {'tools.etags.on': False}})
+    
+    cherrypy.engine.start()
+    cherrypy.engine.block()