Project

General

Profile

Standalone » History » Version 6

Jan Klopper, 2016-08-18 15:35

1 1 Jan Klopper
h1. Standalone
2 1 Jan Klopper
3 2 Elmer de Looff
µ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.
4 1 Jan Klopper
5 2 Elmer de Looff
When running standalone, starting and stopping the web server is done by invoking the router:
6 1 Jan Klopper
7 2 Elmer de Looff
<pre><code class="bash">
8 2 Elmer de Looff
$ python uweb_info/www/router.py 
9 2 Elmer de Looff
Usage: router.py start | stop | restart
10 2 Elmer de Looff
</code></pre>
11 1 Jan Klopper
12 2 Elmer de Looff
An argument needs to be provided to start/stop or restart the router. Providing this will initiate the obvious action.
13 1 Jan Klopper
14 2 Elmer de Looff
h2. Expanding your configuration
15 1 Jan Klopper
16 2 Elmer de Looff
The entry point for the standalone project is the [[request router]], with a few additional global variables that can be used to configure Standalone:
17 1 Jan Klopper
18 2 Elmer de Looff
<pre><code class="python">
19 2 Elmer de Looff
#!/usr/bin/python
20 2 Elmer de Looff
"""A uWeb demonstration project."""
21 1 Jan Klopper
22 2 Elmer de Looff
# uWeb Framework
23 1 Jan Klopper
import uweb
24 2 Elmer de Looff
25 2 Elmer de Looff
# Project's controller
26 2 Elmer de Looff
from uweb.uweb_info import pages
27 2 Elmer de Looff
28 3 Elmer de Looff
# uWeb configuration variables (optional)
29 2 Elmer de Looff
CONFIG = 'example.conf'
30 2 Elmer de Looff
PACKAGE = 'uweb_info'
31 2 Elmer de Looff
32 1 Jan Klopper
PAGE_CLASS = pages.PageMaker
33 1 Jan Klopper
ROUTES = (
34 2 Elmer de Looff
    ('/static/(.*)', 'Static'),
35 2 Elmer de Looff
    ('/(broken.*)', 'FourOhFour'),
36 2 Elmer de Looff
    ('/haltandcatchfire', 'MakeFail'),
37 2 Elmer de Looff
    ('/json', 'Json'),
38 2 Elmer de Looff
    ('/text', 'Text'),
39 2 Elmer de Looff
    ('/redirect/(.*)', 'Redirect'),
40 2 Elmer de Looff
    ('/OpenIDLogin', '_OpenIdInitiate'),
41 2 Elmer de Looff
    ('/OpenIDValidate', '_OpenIdValidate'),
42 2 Elmer de Looff
    ('/ULF-Challenge', '_ULF_Challenge'),
43 2 Elmer de Looff
    ('/ULF-Login', '_ULF_Verify'),
44 2 Elmer de Looff
    ('/(.*)', 'Index'))
45 1 Jan Klopper
46 1 Jan Klopper
uweb.ServerSetup()
47 2 Elmer de Looff
</code></pre>
48 1 Jan Klopper
49 2 Elmer de Looff
Compared to the request router, there are two new global variables here:
50 2 Elmer de Looff
51 2 Elmer de Looff
# @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.
52 4 Elmer de Looff
# @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@*.
53 2 Elmer de Looff
54 2 Elmer de Looff
h1. Standalone configuration
55 2 Elmer de Looff
56 2 Elmer de Looff
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:
57 2 Elmer de Looff
58 2 Elmer de Looff
<pre><code class="ini">
59 1 Jan Klopper
[standalone]
60 2 Elmer de Looff
port = 8082
61 6 Jan Klopper
host = 127.0.0.1
62 2 Elmer de Looff
access_logging = True
63 2 Elmer de Looff
error_logging = True
64 2 Elmer de Looff
</code></pre>
65 1 Jan Klopper
66 5 Arjen Pander
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.
67 2 Elmer de Looff
68 2 Elmer de Looff
h2. Multiple routers on one config file
69 2 Elmer de Looff
70 2 Elmer de Looff
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).
71 2 Elmer de Looff
72 2 Elmer de Looff
<pre><code class="ini">
73 2 Elmer de Looff
[standalone]
74 2 Elmer de Looff
access_logging = True
75 2 Elmer de Looff
error_logging = True
76 2 Elmer de Looff
77 2 Elmer de Looff
[standalone:website]
78 2 Elmer de Looff
port = 8000
79 2 Elmer de Looff
80 2 Elmer de Looff
[standalone:admin]
81 2 Elmer de Looff
port = 8001
82 2 Elmer de Looff
access_logging = False
83 2 Elmer de Looff
</code></pre>
84 2 Elmer de Looff
85 2 Elmer de Looff
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.