A Server for Single-Page Web-Applications
A simple server for developing single-page applications quickly in a team environment.
The core of the server are handlebar templates. Here is one handlebar template that
comes with the site-manager at
Create a new directory demo appliation in a new directory, such as...
mkdir mydemoappcd mydemoapp
Create a new
package.json, declaring site-manager as a dependency.
Declaring the site-manager isn't strictly required, but makes deploying to many systems (such as Heroku) much
easier. Instead of declaring the dependency, one can also install the site-manager globally using
npm install -g site-manager.
Next, we need a
"use strict";var path = require"path";defaultsuseRequireJS = false; // disable the site-manager support for requireJSdefaultshostname = "mydemoapp.jolira.com"; // define the name of the sitedefaultstitle = "My Demo App"; // The title to be displayed in the titlebardefaultshtmlFiles =pathjoin__dirname "content.html" // add some content;return cbundefined defaults;;__dirname module;
Now, all that is remaining is to specify the HTML-fragment to be displayed when we run the site-manager.
To install the dependencies:
npm install -d
To run the example:
$ node_modules/.bin/site-manager --debug --port=3000 .
To run the example on Heroku you need the following ``Procfile`:
web: node_modules/.bin/site-manager --debug --port=$PORT --watch-dirs=false .
http://localhost:3000 to get the example running.
As shown in the example, every site-manager site has configures the site by exporting a function. This function looks like this:
"use strict";// configure the defaults object herereturn cbundefined defaults;;
The default object takes the following parameters:
defaults: The defaults object to be configured. A detailed description of the properties of this object can be found at
public/index.htmlshows how may of these values are used.
cbthe the callback function, which takes two parameters
cb(err, vals). The first parameter should be set to
undefinedunless there is an error to report. The second parameter should be used to pass the configured default object back to the site-manager.
propertiesloaded from a
.config.jsonfile in the project directory.
appthe express.js object used by the site-manager.
Key features of this package are:
.config.jsonfiles from the site directory. The site-manager also loads properties from a
~/.sitemanager.jsonfile, and passes the data to the different sites it serves.
The site-manager can run in multi-site mode, which creates virtual hosts for each module. The hostname is defined in the site is used as the server name of the vhost.
In order to run in multi-site mode, point the site-manager to a directory that contains mutiple sites, such as in
site-manager examples # use the examples directory from the repo
To test sites you have to define the correct hostname. In order to do so, you have to add these names to
To define the hostames used by examples from the site-manager github repo, add the following line to
(assuming you are running the site-manager on your machine):
127.0.0.1 simple.jolira.com advanced.jolira.com
Once this entry has been added, you can access the advanced example as
http://advanced.jolira.com:3000 and the simple
When running in single-site mode, there is no vhosting (as only one site is served). To run the site-manager in single-site mode, point it to a site directory as in:
site-manager examples/simple # use the examples directory from the repo
As there is no virtual hosting, we do not have to define any entry in
/etc/hosts and can access the example at
Debug output is generated when the string
site-manager is part of the value of the
npm install -g jake
Note that Jake is a system-level tool, so it wants to be installed globally.
To execute tests execute: