In order to build your Sausalito Application, you need to create a project. Essentially, a project is a set of directories that contain your code, static files, configuration information, and test data. Every project is identified by a logical URI (e.g. http://www.28msec.com/myapp/). This concept is similar to Java packages. The sausalito script provides an easy to use way to create such a project. The syntax to create a project is as follows:
sausalito create project -d <project_directory> -u <project_logical_URI>
The parameter project_directory is the target directory on your PC or Mac in which all files or your project are kept.
For example, to create a new project with the logical URI http://www.mydomain.com/myapp/ (project_logical_URI) in the directory myapp on your machine just type
sausalito create project -d myapp -u http://www.mydomain.com/myapp/
You should see an output such as
Creating project at: myapp Project URI: http://www.mydomain.com/myapp/ Project created successfully
and have the directory myapp created in your current working directory. Please note that the prefix http://www.28msec.com/ is reserved for namespace URIs.
sausalito test project -d <project_directory> [ -i <ip:port> ]Deploys the project on your machine. That is, a Web server is started on your machine and you are now ready to test your application using a Web browser. When you created the project, Sausalito already created a small “hello world” mini-application for you. (You will learn how to edit and extend it later.)
Per default, the test server is bound to localhost:8080. However, if you wish you can set a different IP address and port. This is important if you would like to run several applications at the same time.
Example:
sausalito test project -d myapp
Now you can start your Web browser and call the following URL:
http://localhost:8080/default/index
You should see a nice green Web page. In fact, you have executed the “index” XQuery function in the “default” module of your pre-configured mini-application. Also try:
http://localhost:8080/unknown
You should see an error because there is no “unknown” module in your mini-application.
Once you have a running project you can start extending and customizing the code. With Sausalito, the whole application can be written using XQuery. So, let us edit the XQuery code. Start your favorite editor and edit the following file:
vi myapp/handlers/default.xq
You can play around with the HTML and the XQuery in this file while the application is deployed. Simply reload the page in the your Web browser to see the effects. You can also add other XQuery functions. If you write a new XQuery function “foo” in the “default” module, then you call this function in your Web browser as follows:
http://localhost:8080/default/foo
You can also pass parameters to your XQuery functions. For instance, try out what happens if you call the following URL in your Web browser (look at the “Parameter” lines at the bottom of the Web page):
http://localhost:8080/default/index?green=great&blue=over
If you want to see how bigger applications are built and what Sausalito and XQuery can do for you (e.g., libraries, database persistence, schemas, RESTful services, etc.), then take a look at the two demo applications that are shipped with Sausalito: Guestbook and TODO.
Once your project is created, debugged, and tested locally on your machine, it can be deployed on 28msec's scalable infrastructure. This way, your application becomes visible to everybody on the Web.
Here's what you need to do in order to deploy the “myapp” application:
sausalito deploy project -d <project_dir> -a <project_name> The “project_dir” as chosen on your local machine when you created the project. “project_name” as chosen in Step 2 (e.g., “myapp28”). For example, call the script in the following way in order to deploy the “myapp” application located in the directory “myapp” and deploy it as “myapp28”:
sausalito deploy project -d myapp -a myapp28
When running the script, the script will prompt you for a user name and password. Please, enter the same user name and password that you chose in Step 1 for managing your applications in the 28msec portal.
The script will upload your XQuery project (i.e., the XQuery source code) and start a Web Server to serve requests for your applications. Once you have run this script, you can do the following things: