Project

General

Profile

Application » History » Version 1

Version 1/4 - Next » - Current version
Elmer de Looff, 2012-11-08 14:42


Application

Initialize uweb project

The easy way to initialize uweb is to type

uweb init [your project name]

This creates a folder in your current directory with the project name.
When you don't pick a name uweb uses 'uweb_project' by default.
You probably want pick a nice name because this is what makes your project unique like a little snow flake.

uweb init snowflake
--------------------------------------------
initializing uweb
--------------------------------------------
cloning uweb source
setting up router
setting up apache config
--------------------------------------------
initialization complete - have fun with uweb
--------------------------------------------

This generates the snowflake uweb project and generates a folder named 'snowflake' in your current directory. The snowflake project contains multiple folders and files.
In the next chapter we'll activate our project locally.

If you already have a project with the same name, uweb gives you a warning and cancels initialization.

Project already excist, use -f (force) to wipe project.

If you somehow completely ruined your project and want a clean start add the 'f' (force) flag to remove your project and execute a clean initialization.

uweb init snowflake -f

The same effect can be recreated by deleting the project and initializing uweb as usual.

Start/stop local webserver

uweb works with router files. A router usually represents a domain. To start a webserver navigate to your router (in the project's router folder) and type 'start'.

python /home/user/snowflake/router/snowflake.py start

Next you can open up your browser and navigate to:

http://localhost:8082/

Uweb uses port 8082 locally by default.
This brings you to the default uweb page which contains the text 'Hello µWeb'.
This means you have successfully setup and started your own uweb project.

To stop you local server, replace the 'start' command with 'stop'

python /home/user/snowflake/router/snowflake.py stop

When you make updates in your router, uweb usually don't update your changes manually.
Type 'restart' to restart your local server with the new configurations.

python /home/user/snowflake/router/snowflake.py restart

Setting up uWeb in Apache

To setup uweb in apache, copy the apache.conf (in the root of your project) to your available apache sites.
Uweb its default domain is your project name followed by local.

ServerName  [project_name].local

change this to the desired domain name.

ServerName  snowflake.com

Next add this domain to your hosts and reload apache.
Now your uweb project should work in Apache.

Warning
Renaming/moving your project will result in a broken apache config file.
When you rename your project, remember to adjust the apache.conf file to the new name / location

Quick router controls

To easily control uweb routers, there are a number of actions on the uWeb application, listed below:

uweb [list|start|stop|restart|add|remove] -n [project name]

Each project you create is added to je uweb router location file.
This file contains the router locations of all your uweb project.
Calling the sites argument will display all projects and there route locations

$ uweb sites
snowflake: /home/codehunger/snowflake/router/snowflake.py

In this example you see only one uweb project.
This project is called 'snowflake' and the router location is '/home/codehunger/snowflake/router/snowflake.py'

To start the 'snowflake' router you can simpely call uweb to start the snowflake router.

$ uweb start -n snowflake
Starting ...

The n option should contain the name of your project.
This could also be used to

restart the router:

$ uweb restart -n snowflake
Stopping ...
Starting ...

stop the router:

$ uweb stop -n snowflake
Stopping ...

When you add a uweb website (from a repository for example), uweb need to be updated.
To add a path to the uwebsites use the 'add' argument.

$ uweb sites
snowflake: /home/codehunger/snowflake/router/snowflake.py
$ uweb add -n foreign_snowflake -r /home/codehunger/foreign_snowflake/router/snowflake.py
$ uweb sites
foreign_snowflake: /home/codehunger/foreign_snowflake/router/snowflake.py
snowflake: /home/codehunger/snowflake/router/snowflake.py

The -n option contains the project name.
The -r is the router location.

In this example a project is added to the uweb sites.
As you can see 'uweb sites' first printed 1 record and after adding a new site it printed 2 records.

When you move your project the router links are not directing to your router anymore.
You can update your router location with the -f (force) flag.

$ uweb add -f -n foreign_snowflake -r /home/bob/snowflake/router/snowflake.py

This updates the 'foreign_snowflake' record with a new router location.
The previous router location is overwritten by the new location.