summaryrefslogtreecommitdiff
path: root/docs/source/deployment.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/source/deployment.rst')
-rw-r--r--docs/source/deployment.rst80
1 files changed, 77 insertions, 3 deletions
diff --git a/docs/source/deployment.rst b/docs/source/deployment.rst
index b95ab39..9cc1fec 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.
@@ -93,7 +93,7 @@ performance reasons). There are several popular ways to accomplish this. Here
are two:
1. Set up a proxy server (such as `nginx <http://nginx.org/en>`__, `cherokee
- <http://www.cherokee-project.com>`__, or `lighttpd
+ <http://www.cherokee-project.com>`__, :ref:`cherrypy`, or `lighttpd
<http://www.lighttpd.net/>`__) to serve static files and proxy application
requests through to your WSGI application:
@@ -204,3 +204,77 @@ Pecan's default project::
$ pecan create simpleapp && cd simpleapp
$ python setup.py develop
$ gunicorn_pecan config.py
+
+
+.. _cherrypy:
+
+CherryPy
+++++++++
+
+`CherryPy <http://cherrypy.org/>`__ offers a pure Python HTTP/1.1-compliant WSGI
+thread-pooled web server. It can support 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 served. This is how the script (named ``run.py``) looks::
+
+ 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
+ # necessary for some CherryPy machinery
+ 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 start the server, simply call it with the Python executable::
+
+ $ python run.py