Standalone » History » Version 5
Version 4 (Elmer de Looff, 2012-05-10 18:22) → Version 5/6 (Arjen Pander, 2015-03-10 15:32)
h1. 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:
<pre><code class="bash">
$ python uweb_info/www/router.py
Usage: router.py start | stop | restart
</code></pre>
An argument needs to be provided to start/stop or restart the router. Providing this will initiate the obvious action.
h2. 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:
<pre><code class="python">
#!/usr/bin/python
"""A uWeb demonstration project."""
# uWeb Framework
import uweb
# Project's controller
from uweb.uweb_info import pages
# uWeb configuration variables (optional)
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()
</code></pre>
Compared to the request router, there are two new global variables here:
# @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.
# @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@*.
h1. 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:
<pre><code class="ini">
[standalone]
port = 8082
access_logging = True
error_logging = True
</code></pre>
Running the standalone web server on a different port is a matter of specifying the new port and (re)starting the process. True/False True/Fales values can be passed along as strings, or as integers depending on your preference.
h2. 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).
<pre><code class="ini">
[standalone]
access_logging = True
error_logging = True
[standalone:website]
port = 8000
[standalone:admin]
port = 8001
access_logging = False
</code></pre>
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.
µ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:
<pre><code class="bash">
$ python uweb_info/www/router.py
Usage: router.py start | stop | restart
</code></pre>
An argument needs to be provided to start/stop or restart the router. Providing this will initiate the obvious action.
h2. 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:
<pre><code class="python">
#!/usr/bin/python
"""A uWeb demonstration project."""
# uWeb Framework
import uweb
# Project's controller
from uweb.uweb_info import pages
# uWeb configuration variables (optional)
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()
</code></pre>
Compared to the request router, there are two new global variables here:
# @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.
# @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@*.
h1. 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:
<pre><code class="ini">
[standalone]
port = 8082
access_logging = True
error_logging = True
</code></pre>
Running the standalone web server on a different port is a matter of specifying the new port and (re)starting the process. True/False True/Fales values can be passed along as strings, or as integers depending on your preference.
h2. 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).
<pre><code class="ini">
[standalone]
access_logging = True
error_logging = True
[standalone:website]
port = 8000
[standalone:admin]
port = 8001
access_logging = False
</code></pre>
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.