summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlfredo Deza <alfredodeza@gmail.com>2013-07-03 11:10:20 -0400
committerAlfredo Deza <alfredodeza@gmail.com>2013-07-08 12:12:01 -0400
commit86c367213a8bb7dae3c2819a3bde81e52e8747db (patch)
tree2be0caa40b17f3d8096d31447a92264fdd7da91a /docs
parent060f878fb52a629263c848177e929196910c04ba (diff)
downloadpecan-86c367213a8bb7dae3c2819a3bde81e52e8747db.tar.gz
Add the CheryPy section
Diffstat (limited to 'docs')
-rw-r--r--docs/source/deployment.rst75
1 files changed, 73 insertions, 2 deletions
diff --git a/docs/source/deployment.rst b/docs/source/deployment.rst
index b95ab39..1f6e11f 100644
--- a/docs/source/deployment.rst
+++ b/docs/source/deployment.rst
@@ -11,7 +11,7 @@ probably vary.
.. ::
- While Pecan comes packaged with a simple server *for development use*
+ While Pecan comes packaged with a simple server *for development use*
(``pecan serve``), using a *production-ready* server similar to the ones
described in this document is **very highly encouraged**.
@@ -82,7 +82,7 @@ Considerations for Static Files
-------------------------------
Pecan comes with static file serving (e.g., CSS, Javascript, images)
-middleware which is **not** recommended for use in production.
+middleware which is **not** recommended for use in production.
In production, Pecan doesn't serve media files itself; it leaves that job to
whichever web server you choose.
@@ -204,3 +204,74 @@ Pecan's default project::
$ pecan create simpleapp && cd simpleapp
$ python setup.py develop
$ gunicorn_pecan config.py
+
+
+CherryPy
+++++++++
+
+`CherryPy <http://cherrypy.org/>`__ offers a pure Python HTTP/1.1-compliant WSGI
+thread-pooled webserver. It can support pure WSGI Pecan applications easily and
+even serve static files like a production server would do.
+
+The examples that follow are geared towards using CherryPy as the server in
+charge of handling a Pecan app along with serving static files.
+
+::
+
+ $ pip install cherrypy
+ $ pecan create simpleapp && cd simpleapp
+ $ python setup.py develop
+
+To run with CherryPy, the easiest approach is to create a script in the root of
+the project (alongside ``setup.py``), so that we can describe how our example
+application should be handled::
+
+ import os
+ import cherrypy
+ from cherrypy import wsgiserver
+
+ from pecan import deploy
+
+ simpleapp_wsgi_app = deploy('/path/to/production_config.py')
+
+ public_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'public'))
+
+ # A dummy class for our Root object
+ class Root(object):
+ pass
+
+ def make_static_config(static_dir_name):
+ """
+ All custom static configurations are set here, since most are common, it
+ makes sense to generate them just once.
+ """
+ static_path = os.path.join('/', static_dir_name)
+ path = os.path.join(public_path, static_dir_name)
+ configuration = {
+ static_path: {
+ 'tools.staticdir.on': True,
+ 'tools.staticdir.dir': path
+ }
+ }
+ return cherrypy.tree.mount(Root(), '/', config=configuration)
+
+ # Assuming your app has media on diferent paths, like 'css', and 'images'
+ application = wsgiserver.WSGIPathInfoDispatcher({
+ '/': simpleapp_wsgi_app,
+ '/css': make_static_config('css'),
+ '/images': make_static_config('images')
+ }
+ )
+
+ server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), application,
+ server_name='simpleapp')
+
+ try:
+ server.start()
+ except KeyboardInterrupt:
+ print "Terminating server..."
+ server.stop()
+
+To run the above, simply call it with the Python executable::
+
+ $ python run.py