Skip to content

Configuration

Jason edited this page Oct 22, 2014 · 5 revisions

There are two configuration files for Lazo. Lazo will load these two files when the application is started.

app.json

app/app.json is used to configure application level settings such as routes. app.json is a required file.

Routes

The routes property is used define the routes for an application.

Lazo uses Backbone style routes. Routes are mapped to a component and an optional controller action for the component. index is the default action methond for a component. In addition to mapping to components routes can optionally map to layouts, which are applied to the route response. A default layout can be defined in app.json as well { defaultLayout: 'some_layout' }.

{
    // set up routes
    "routes": {
        "":                 { "component": "home", "servers": ["primary", "another_server"] },
        "here(/)":          "here",
        "there(/)":         "there#someAction",
        "everywhere(/)":    { "component": "everywhere", "layout": "fancy" },
    },
    // define a default layout
    "defaultLayout": "regular"
}

A Route can be targeted at particular server instances. If a servers array property is not provided then the route is implicitly assigned to the primary server instance. If a servers array property is provided then server instances, including the primary, must be explicitly specified as elements in the array.

JavaScript and Links

Application level JavaScript and CSS can be defined using the js and css properties respectively.

JavaScript is loaded via RequireJS. The baseUrl is the application root, so relative paths minus the file extension, '.js', will work in addition to absolute paths with the file extension, '.js'.

{
    "css": ["/app/client/application.css"],
    "js": ["app/client/someAppLevelCode"],
    "imports": ["/app/imports/someAppLevelImport.html"]
}

conf.json

conf.json is used to override and extend Lazo default settings . It is an optional file unlike app/app.json. A deep merge is done between application conf.json and Lazo defaults. Below is the default configuration set by Lazo.

{
    "server": {
        "instances": {
            "primary": {
                "port": 8080
            }
        },
        "monitor": {
            "on": false,
            "options": {}
        },
        "defaults": {
            "timeout": {
                "server": 30000,
                "client": 30000
            },
            "maxBytes": 10485760,
            "debug": false,
            "state": {
                "cookies": {
                    "failAction": "log",
                    "strictHeader": false
                }
            }
        },
        "maxSockets": 500
    },
    "requirejs": {
        "shim": {
            "handlebars": {
                "exports": "Handlebars"
            }
        },
        "paths": {} // these are merged in by Lazo at start
    },
    "libPath": "/lib/optimized/lib.js"
}

Server Instances

Multiple servers can be instantiated using the server.instances property. These properties and the server.default are used to create a pack of Hapi server instances. The server instances are responsible for responding to route requests with controller actions, handling CRUD operations for models and collections, and executing methods on the server.

// add a server instance
{
    "server": {
        "instances": {
            "another_server": {
                "port": 9000
            }
        }
    }
}
SSL

A secure sockets layer can be defined for a server instance using the tls property. tls.key and tls.cert paths should be relative to the application root directory or absolute paths.

// add an ssl server instance
{
    "server": {
        "instances": {
            "ssl": {
                "port": 443,
                "tls": {
                    "key": "cpf-key.pem",
                    "cert": "cpf-cert.pem"
                }
            }
        }
    }
}

Server Monitoring

Lazo uses Good for monitoring a server pack. Options are passed directly to Good when registering the plugin. Monitoring is turned off by default and no default options are set by Lazo.

// turn on monitoring
{
    "server": {
        "monitor": {
            "on": true,
            "options": {
                subscribers: {
                    'console': ['ops', 'request', 'log', 'error']
                }
            }
        }
    }
}

Server Defaults

The server.defaults values are merged in with each server instance. The order of precedence for merged values is application server instances, application defaults, Lazo server instances, and finally Lazo defaults.

// decrease default timeouts
{
    "server": {
        "defaults": {
            "timeout": {
                "server": 15000,
                "client": 15000
            }
        }
    }
}

Module Loader Configuration

The requirejs property is used to augment the configuration that Lazo creates for RequireJS.