The process of deploying a WebStack application should be as straightforward as taking some adapter or "glue" code and either running it or using the deployment processes of the server environment or framework in which the application will be living.
What adapter or "glue" code does is to set up your applications main
resource object and to hook that object up with the underlying server
environment. For the MyApplication
example, together with a simple environment,
looks something like
this:
from WebStack.Adapters.BaseHTTPRequestHandler import deploy # import the support for the server environment
from MyApplication import MyResource # import the main resource class
print "Serving..."
deploy(MyResource()) # connect a resource object to the server environment
In the case of BaseHTTPRequestHandler, which is a module in the
Python standard library, you can just run this code, making sure that
the MyApplication
module or package is on your PYTHONPATH
.
Then, you can visit http://localhost:8080
in your
browser and see the result.
The
above example suggested the direct deployment of a specific resource,
and this was quickly achieved by instantiating the resource within the
call to the deploy
function. However, it may be more
desirable to have an application provide a function within the module
or package containing the resources which causes their initialisation
in a more sophisticated fashion and which returns a resource object
ready for use. Let us suppose that the MyApplication
module provides a function for this purpose:
from WebStack.Adapters.BaseHTTPRequestHandler import deploy # import the support for the server environment
from MyApplication import get_site_map # import the function indicating the "root" resource
print "Serving..."
deploy(get_site_map()) # connect a resource object to the server environment
Whilst
this appears to be trading one name for another, the intent is really
to provide a layer of abstraction which hides the details of resource
classes from the deployment code, even if the get_site_map
function is only as simple as the following:
def get_site_map():
return MyResource()
Of course, this function may be made more complicated as the need arises.
Unfortunately, not all server environments can be connected up with applications this easily. Some environments require special classes and functions to be defined in the adapter code in order for applications to be properly integrated into those environments. A summary of the requirements of each environment can be found in "Writing Adapters".