Basic Examples

More Advanced Examples


    var bricks = require('bricks');
    
    var appServer = new bricks.appserver();

    appServer.addRoute("/hello", function(request, response) {
        response.write("Hello World!");
        response.end();
    });

    appServer.addRoute(".+", appServer.plugins.fourohfour);

    var server = appServer.createServer();
    server.listen(3000);


    var bricks = require('bricks');
    
    var appServer = new bricks.appserver();

    var redirects = [
      {
        path: "^/$",
        url:  "/index.html"
      }
    ];

    appServer.addRoute(".+", appServer.plugins.redirect, { section: "pre", routes: redirects });

    appServer.addRoute(".+", appServer.plugins.filehandler, { basedir: "./htdocs" });
    appServer.addRoute(".+", appServer.plugins.fourohfour);

    appServer.addRoute(".+", appserver.plugins.loghandler, { section: 'final', filename: "./logs/access.log" });

    var server = appServer.createServer();
    server.listen(3000);


    var bricks = require('bricks');

    var simplePlugin = {
        hits: 0,
        init: function (options) {
          options = options || { };
          hits = options.hits || 0;
        },
        plugin: function (request, response) {
          response.write(++hits + " hits so far");
          response.end();
        }
    };

    var appServer = new bricks.appserver();
    
    appServer.addRoute(".+", simplePlugin);

    var server = appServer.createServer();
    server.listen(3000);


    require('date-utils');
    var bricks = require('bricks');

    var appServer = new bricks.appserver();

    var session = {
      section: "pre",
      session: "chocolatechip",
      cookie: {
        expires: new Date().addYears(1),
        httpOnly: false
      }
    };

    appServer.addRoute(/.+/, appServer.plugins.sessionhandler, session);
    appServer.addRoute(/.+/, appServer.plugins.filehandler, { basedir: '.' });
    appServer.addRoute(/.+/, appServer.plugins.fourohfour);

    var server = appServer.createServer();
    server.listen(3000);


    var bricks = require('bricks');

    function exactStringMatch(route, path, request) {
        if (typeof(route) === 'function') {
            try {
                var match = route(path, request);
                if (match) {
                    return true;
                }
            } catch(error) {
                this.emit('route.fatal', error);
            }
        } else {
            if ((typeof(route) === 'string') && path === route) {
                return true;
            }
        }

        return false;
    };
    
    var appServer = new bricks.appserver({ checkRoute: exactStringMatch });

    appServer.addRoute("/hello", function (request, response) { response.write("Hello"); response.end(); });
    appServer.addRoute(/.+/, appServer.plugins.fourohfour);

    var server = appServer.createServer();
    server.listen(3000);


    require('date-utils');
    var bricks = require('bricks');
    var keys   = require('keygrip')();

    var appServer = new bricks.appserver();

    var session = {
      section: "pre",
      session: "chocolatechip",
      cookie: {
        expires: new Date().addYears(1),
        httpOnly: false
      }
    };

    appServer.addRoute(/.+/, appServer.plugins.sessionhandler, session);
    appServer.addRoute(/.+/, appServer.plugins.filehandler, { basedir: '.' });
    appServer.addRoute(/.+/, appServer.plugins.fourohfour);

    var server = appServer.createServer();
    server.listen(3000);