Project

General

Profile

Standalone » History » Version 2

« Previous - Version 2/6 (diff) - Next » - Current version
Elmer de Looff, 2012-05-07 16:44


Standalone

µWeb's standalone mode allows you to develop, run and test your website/application without needing a web server on your local machine. This enables rapid application development and when it's time to migrate over to Apache, everything will work the same way it did on here.

When running standalone, starting and stopping the web server is done by invoking the router:

$ python uweb_info/www/router.py 
Usage: router.py start | stop | restart

An argument needs to be provided to start/stop or restart the router. Providing this will initiate the obvious action.

Expanding your configuration

The entry point for the standalone project is the request router, with a few additional global variables that can be used to configure Standalone:

#!/usr/bin/python
"""A uWeb demonstration project.""" 

# uWeb Framework
import uweb

# Project's controller
from uweb.uweb_info import pages

# uWeb standalone configuration keys
CONFIG = 'example.conf'
PACKAGE = 'uweb_info'

PAGE_CLASS = pages.PageMaker
ROUTES = (
    ('/static/(.*)', 'Static'),
    ('/(broken.*)', 'FourOhFour'),
    ('/haltandcatchfire', 'MakeFail'),
    ('/json', 'Json'),
    ('/text', 'Text'),
    ('/redirect/(.*)', 'Redirect'),
    ('/OpenIDLogin', '_OpenIdInitiate'),
    ('/OpenIDValidate', '_OpenIdValidate'),
    ('/ULF-Challenge', '_ULF_Challenge'),
    ('/ULF-Login', '_ULF_Verify'),
    ('/(.*)', 'Index'))

uweb.ServerSetup()

Compared to the request router, there are two new global variables here:

  1. CONFIG is used to indicate the path for the configuration file, if there is any. This is a path to the configuration file (explained below), relative from the router path. In this router, the configuration file is a file named example.conf in the same directory as the router. If there is no configuration file, this variable should be omitted.
  2. PACKAGE is used to indicate the package name of the project. The package name is used to group logfiles by. Logfiles will be automatically created and written to either /var/log/underdark/$PACKAGE/ or ~/.underdark/$PACKAGE/, whichever is writable. If no explicit PACKAGE variable is set, the name of the directory one above the router directory will be used. In the case of the example project, the router is in a directory uweb/uweb_info/www/, meaning that the package name is uweb_info

Standalone configuration

The standalone server can be configured to bind to a specific port, and enable/disable request logging. The following is an explicit definition of the default settings:

[standalone]
port = 8082
access_logging = True
error_logging = True

Running the standalone web server on a different port is a matter of specifying the new port and (re)starting the process. True/Fales values can be passed along as strings, or as integers depending on your preference.

Multiple routers on one config file

You can have multiple routers (in standalone mode) using a single configuration file. This can be beneficial if they share many other settings, but still need their own port allocations (because only one webserver can bind to a given port). Standalone settings can be specifically assigned to a single router module, thereby allowing multiple router configurations (as long as they have differing filenames).

[standalone]
access_logging = True
error_logging = True

[standalone:website]
port = 8000

[standalone:admin]
port = 8001
access_logging = False

This configuration block explicitly enables logging for all routers, but then disables access logging for the admin router. The website router will run on port 8000, but the admin router will run on port 8001.