WebStack

docs/deploying.html

732:7f1f02b485f8
2007-11-12 paulb [project @ 2007-11-12 00:50:03 by paulb] Introduced base classes for common authentication activities. Made cookie usage "safe" for usernames containing ":" characters. Added support for OpenID signatures.
     1 <?xml version="1.0" encoding="iso-8859-1"?>     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     3 <html xmlns="http://www.w3.org/1999/xhtml">     4 <head>     5   <title>Deploying a WebStack Application</title>     6   <link href="styles.css" rel="stylesheet" type="text/css" />     7 </head>     8 <body>     9 <h1>Deploying a WebStack Application</h1>    10 <p>The process of deploying a WebStack application should be as    11 straightforward as taking some adapter or "glue" code and either    12 running it    13 or using the deployment processes of the server environment or    14 framework in    15 which the application will be living.</p>    16     17 <h2>The Adapter Code</h2>    18 <p>What adapter or "glue" code does is to set up your applications main    19 resource object and to hook that object up with the underlying server    20 environment. For the&nbsp;<code>MyApplication</code> <a href="resources.html">example</a>, together with a simple environment,    21 looks something like    22 this:</p>    23 <pre>from WebStack.Adapters.BaseHTTPRequestHandler import deploy    # import the support for the server environment<br />from MyApplication import MyResource                           # import the main resource class<br />print "Serving..."<br />deploy(MyResource())                                           # connect a resource object to the server environment</pre>    24 <p>In the case of BaseHTTPRequestHandler, which is a module in the    25 Python standard library, you can just run this code, making sure that    26 the <code>MyApplication</code> module or package is on your <code>PYTHONPATH</code>.    27 Then, you can visit&nbsp;<code>http://localhost:8080</code> in your    28 browser and see the result.</p>    29     30 <h3>Root Resources and Site Maps</h3><p>The    31 above example suggested the direct deployment of a specific resource,    32 and this was quickly achieved by instantiating the resource within the    33 call to the <code>deploy</code> function. However, it may be more    34 desirable to have an application provide a function within the module    35 or package containing the resources which causes their initialisation    36 in a more sophisticated fashion and which returns a resource object    37 ready for use. Let us suppose that the <code>MyApplication</code> module provides a function for this purpose:</p><pre>from WebStack.Adapters.BaseHTTPRequestHandler import deploy    # import the support for the server environment<br />from MyApplication import get_site_map                         # import the function indicating the "root" resource<br />print "Serving..."<br />deploy(get_site_map())                                         # connect a resource object to the server environment</pre><p>Whilst    38 this appears to be trading one name for another, the intent is really    39 to provide a layer of abstraction which hides the details of resource    40 classes from the deployment code, even if the <code>get_site_map</code> function is only as simple as the following:</p><pre>def get_site_map():<br />    return MyResource()</pre><p>Of course, this function may be made more complicated as the need arises.</p>    41     42 <h3>More Demanding Adapter Code</h3>    43 <p>Unfortunately, not all server environments can be connected up with    44 applications this easily. Some environments require special classes and    45 functions to be defined in the adapter code in order for    46 applications to    47 be properly integrated into those environments. A summary of the    48 requirements of each environment can be found in <a href="writing-adapters.html">"Writing Adapters"</a>.</p>    49     50 <h2>The Deployment Process</h2>    51 <ul>    52   <li><a href="writing-adapters.html">Writing Adapters</a></li>    53   <li><a href="pythonpath.html">Getting PYTHONPATH Right</a></li>    54   <li><a href="deploying-applications.html">Deploying an Application</a></li>    55 </ul>    56 </body></html>