µWeb documentation - 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:

1$ python uweb_info/www/router.py
2Usage: 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:

 2"""A uWeb demonstration project."""
 4# uWeb Framework
 5import uweb
 7# Project's controller
 8from uweb.uweb_info import pages
10# uWeb configuration variables (optional)
11CONFIG = 'example.conf'
12PACKAGE = 'uweb_info'
14PAGE_CLASS = pages.PageMaker
15ROUTES = (
16    ('/static/(.*)', 'Static'),
17    ('/(broken.*)', 'FourOhFour'),
18    ('/haltandcatchfire', 'MakeFail'),
19    ('/json', 'Json'),
20    ('/text', 'Text'),
21    ('/redirect/(.*)', 'Redirect'),
22    ('/OpenIDLogin', '_OpenIdInitiate'),
23    ('/OpenIDValidate', '_OpenIdValidate'),
24    ('/ULF-Challenge', '_ULF_Challenge'),
25    ('/ULF-Login', '_ULF_Verify'),
26    ('/(.*)', 'Index'))

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:

2port = 8082
3access_logging = True
4error_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/False 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).

 2access_logging = True
 3error_logging = True
 6port = 8000
 9port = 8001
10access_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.

blog comments powered by Disqus