Commits

Patrick Veverka committed cfff351

adding connect

Comments (0)

Files changed (261)

node_modules/connect/.npmignore

+*.markdown
+*.md
+.git*
+Makefile
+benchmarks/
+docs/
+examples/
+install.sh
+support/
+test/
+.DS_Store

node_modules/connect/LICENSE

+(The MIT License)
+
+Copyright (c) 2010 Sencha Inc.
+Copyright (c) 2011 LearnBoost
+Copyright (c) 2011 TJ Holowaychuk
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node_modules/connect/index.js

+
+module.exports = require('./lib/connect');

node_modules/connect/lib/cache.js

+
+/*!
+ * Connect - Cache
+ * Copyright(c) 2011 Sencha Inc.
+ * MIT Licensed
+ */
+
+/**
+ * Expose `Cache`.
+ */
+
+module.exports = Cache;
+
+/**
+ * LRU cache store.
+ *
+ * @param {Number} limit
+ * @api private
+ */
+
+function Cache(limit) {
+  this.store = {};
+  this.keys = [];
+  this.limit = limit;
+}
+
+/**
+ * Touch `key`, promoting the object.
+ *
+ * @param {String} key
+ * @param {Number} i
+ * @api private
+ */
+
+Cache.prototype.touch = function(key, i){
+  this.keys.splice(i,1);
+  this.keys.push(key);
+};
+
+/**
+ * Remove `key`.
+ *
+ * @param {String} key
+ * @api private
+ */
+
+Cache.prototype.remove = function(key){
+  delete this.store[key];
+};
+
+/**
+ * Get the object stored for `key`.
+ *
+ * @param {String} key
+ * @return {Array}
+ * @api private
+ */
+
+Cache.prototype.get = function(key){
+  return this.store[key];
+};
+
+/**
+ * Add a cache `key`.
+ *
+ * @param {String} key
+ * @return {Array}
+ * @api private
+ */
+
+Cache.prototype.add = function(key){
+  // initialize store
+  var len = this.keys.push(key);
+
+  // limit reached, invalid LRU
+  if (len > this.limit) this.remove(this.keys.shift());
+
+  var arr = this.store[key] = [];
+  arr.createdAt = new Date;
+  return arr;
+};

node_modules/connect/lib/connect.js

+
+/*!
+ * Connect
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var HTTPServer = require('./http').Server
+  , HTTPSServer = require('./https').Server
+  , fs = require('fs');
+
+// node patches
+
+require('./patch');
+
+// expose createServer() as the module
+
+exports = module.exports = createServer;
+
+/**
+ * Framework version.
+ */
+
+exports.version = '1.8.5';
+
+/**
+ * Initialize a new `connect.HTTPServer` with the middleware
+ * passed to this function. When an object is passed _first_,
+ * we assume these are the tls options, and return a `connect.HTTPSServer`.
+ *
+ * Examples:
+ *
+ * An example HTTP server, accepting several middleware.
+ *
+ *     var server = connect.createServer(
+ *         connect.logger()
+ *       , connect.static(__dirname + '/public')
+ *     );
+ *
+ * An HTTPS server, utilizing the same middleware as above.
+ *
+ *     var server = connect.createServer(
+ *         { key: key, cert: cert }
+ *       , connect.logger()
+ *       , connect.static(__dirname + '/public')
+ *     );
+ *
+ * Alternatively with connect 1.0 we may omit `createServer()`.
+ *
+ *     connect(
+ *         connect.logger()
+ *       , connect.static(__dirname + '/public')
+ *     ).listen(3000);
+ *
+ * @param  {Object|Function} ...
+ * @return {Server}
+ * @api public
+ */
+
+function createServer() {
+  if ('object' == typeof arguments[0]) {
+    return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
+  } else {
+    return new HTTPServer(Array.prototype.slice.call(arguments));
+  }
+};
+
+// support connect.createServer()
+
+exports.createServer = createServer;
+
+// auto-load getters
+
+exports.middleware = {};
+
+/**
+ * Auto-load bundled middleware with getters.
+ */
+
+fs.readdirSync(__dirname + '/middleware').forEach(function(filename){
+  if (/\.js$/.test(filename)) {
+    var name = filename.substr(0, filename.lastIndexOf('.'));
+    exports.middleware.__defineGetter__(name, function(){
+      return require('./middleware/' + name);
+    });
+  }
+});
+
+// expose utils
+
+exports.utils = require('./utils');
+
+// expose getters as first-class exports
+
+exports.utils.merge(exports, exports.middleware);
+
+// expose constructors
+
+exports.HTTPServer = HTTPServer;
+exports.HTTPSServer = HTTPSServer;
+

node_modules/connect/lib/http.js

+
+/*!
+ * Connect - HTTPServer
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var http = require('http')
+  , parse = require('url').parse
+  , assert = require('assert');
+
+// environment
+
+var env = process.env.NODE_ENV || 'development';
+
+/**
+ * Initialize a new `Server` with the given `middleware`.
+ *
+ * Examples:
+ *
+ *     var server = connect.createServer(
+ *         connect.favicon()
+ *       , connect.logger()
+ *       , connect.static(__dirname + '/public')
+ *     );
+ *
+ * @params {Array} middleware 
+ * @return {Server}
+ * @api public
+ */
+
+var Server = exports.Server = function HTTPServer(middleware) {
+  this.stack = [];
+  middleware.forEach(function(fn){
+    this.use(fn);
+  }, this);
+  http.Server.call(this, this.handle);
+};
+
+/**
+ * Inherit from `http.Server.prototype`.
+ */
+
+Server.prototype.__proto__ = http.Server.prototype;
+
+/**
+ * Utilize the given middleware `handle` to the given `route`,
+ * defaulting to _/_. This "route" is the mount-point for the
+ * middleware, when given a value other than _/_ the middleware
+ * is only effective when that segment is present in the request's
+ * pathname.
+ *
+ * For example if we were to mount a function at _/admin_, it would
+ * be invoked on _/admin_, and _/admin/settings_, however it would
+ * not be invoked for _/_, or _/posts_.
+ *
+ * This is effectively the same as passing middleware to `connect.createServer()`,
+ * however provides a progressive api.
+ *
+ * Examples:
+ *
+ *      var server = connect.createServer();
+ *      server.use(connect.favicon());
+ *      server.use(connect.logger());
+ *      server.use(connect.static(__dirname + '/public'));
+ *
+ * If we wanted to prefix static files with _/public_, we could
+ * "mount" the `static()` middleware:
+ *
+ *      server.use('/public', connect.static(__dirname + '/public'));
+ *
+ * This api is chainable, meaning the following is valid:
+ *
+ *      connect.createServer()
+ *        .use(connect.favicon())
+ *        .use(connect.logger())
+ *        .use(connect.static(__dirname + '/public'))
+ *        .listen(3000);
+ *
+ * @param {String|Function} route or handle
+ * @param {Function} handle
+ * @return {Server}
+ * @api public
+ */
+
+Server.prototype.use = function(route, handle){
+  this.route = '/';
+
+  // default route to '/'
+  if ('string' != typeof route) {
+    handle = route;
+    route = '/';
+  }
+
+  // wrap sub-apps
+  if ('function' == typeof handle.handle) {
+    var server = handle;
+    server.route = route;
+    handle = function(req, res, next) {
+      server.handle(req, res, next);
+    };
+  }
+
+  // wrap vanilla http.Servers
+  if (handle instanceof http.Server) {
+    handle = handle.listeners('request')[0];
+  }
+
+  // normalize route to not trail with slash
+  if ('/' == route[route.length - 1]) {
+    route = route.substr(0, route.length - 1);
+  }
+
+  // add the middleware
+  this.stack.push({ route: route, handle: handle });
+
+  // allow chaining
+  return this;
+};
+
+/**
+ * Handle server requests, punting them down
+ * the middleware stack.
+ *
+ * @api private
+ */
+
+Server.prototype.handle = function(req, res, out) {
+  var writeHead = res.writeHead
+    , stack = this.stack
+    , removed = ''
+    , index = 0;
+
+  function next(err) {
+    var layer, path, c;
+    req.url = removed + req.url;
+    req.originalUrl = req.originalUrl || req.url;
+    removed = '';
+
+    layer = stack[index++];
+
+    // all done
+    if (!layer || res.headerSent) {
+      // but wait! we have a parent
+      if (out) return out(err);
+
+      // error
+      if (err) {
+        var msg = 'production' == env
+          ? 'Internal Server Error'
+          : err.stack || err.toString();
+
+        // output to stderr in a non-test env
+        if ('test' != env) console.error(err.stack || err.toString());
+
+        // unable to respond
+        if (res.headerSent) return req.socket.destroy();
+
+        res.statusCode = 500;
+        res.setHeader('Content-Type', 'text/plain');
+        if ('HEAD' == req.method) return res.end();
+        res.end(msg);
+      } else {
+        res.statusCode = 404;
+        res.setHeader('Content-Type', 'text/plain');
+        if ('HEAD' == req.method) return res.end();
+        res.end('Cannot ' + req.method + ' ' + req.url);
+      }
+      return;
+    }
+
+    try {
+      path = parse(req.url).pathname;
+      if (undefined == path) path = '/';
+
+      // skip this layer if the route doesn't match.
+      if (0 != path.indexOf(layer.route)) return next(err);
+
+      c = path[layer.route.length];
+      if (c && '/' != c && '.' != c) return next(err);
+
+      // Call the layer handler
+      // Trim off the part of the url that matches the route
+      removed = layer.route;
+      req.url = req.url.substr(removed.length);
+
+      // Ensure leading slash
+      if ('/' != req.url[0]) req.url = '/' + req.url;
+
+      var arity = layer.handle.length;
+      if (err) {
+        if (arity === 4) {
+          layer.handle(err, req, res, next);
+        } else {
+          next(err);
+        }
+      } else if (arity < 4) {
+        layer.handle(req, res, next);
+      } else {
+        next();
+      }
+    } catch (e) {
+      if (e instanceof assert.AssertionError) {
+        console.error(e.stack + '\n');
+        next(e);
+      } else {
+        next(e);
+      }
+    }
+  }
+  next();
+};

node_modules/connect/lib/https.js

+
+/*!
+ * Connect - HTTPServer
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var HTTPServer = require('./http').Server
+  , https = require('https');
+
+/**
+ * Initialize a new `Server` with the given
+ *`options` and `middleware`. The HTTPS api
+ * is identical to the [HTTP](http.html) server,
+ * however TLS `options` must be provided before
+ * passing in the optional middleware.
+ *
+ * @params {Object} options
+ * @params {Array} middleawre
+ * @return {Server}
+ * @api public
+ */
+
+var Server = exports.Server = function HTTPSServer(options, middleware) {
+  this.stack = [];
+  middleware.forEach(function(fn){
+    this.use(fn);
+  }, this);
+  https.Server.call(this, options, this.handle);
+};
+
+/**
+ * Inherit from `http.Server.prototype`.
+ */
+
+Server.prototype.__proto__ = https.Server.prototype;
+
+// mixin HTTPServer methods
+
+Object.keys(HTTPServer.prototype).forEach(function(method){
+  Server.prototype[method] = HTTPServer.prototype[method];
+});

node_modules/connect/lib/index.js

+
+/**
+ * # Connect
+ *
+ * Connect is a middleware framework for node,
+ * shipping with over 11 bundled middleware and a rich choice of
+ * [3rd-party middleware](https://github.com/senchalabs/connect/wiki).
+ *
+ * Installation:
+ * 
+ *     $ npm install connect
+ * 
+ * API:
+ *
+ *  - [connect](connect.html) general
+ *  - [http](http.html) http server
+ *  - [https](https.html) https server
+ *
+ * Middleware:
+ *
+ *  - [logger](middleware-logger.html) request logger with custom format support
+ *  - [csrf](middleware-csrf.html) Cross-site request forgery protection
+ *  - [basicAuth](middleware-basicAuth.html) basic http authentication
+ *  - [bodyParser](middleware-bodyParser.html) extensible request body parser
+ *  - [cookieParser](middleware-cookieParser.html) cookie parser
+ *  - [session](middleware-session.html) session management support with bundled [MemoryStore](middleware-session-memory.html)
+ *  - [compiler](middleware-compiler.html) static asset compiler (sass, less, coffee-script, etc)
+ *  - [methodOverride](middleware-methodOverride.html) faux HTTP method support
+ *  - [responseTime](middleware-responseTime.html) calculates response-time and exposes via X-Response-Time
+ *  - [router](middleware-router.html) provides rich Sinatra / Express-like routing
+ *  - [staticCache](middleware-staticCache.html) memory cache layer for the static() middleware
+ *  - [static](middleware-static.html) streaming static file server supporting `Range` and more
+ *  - [directory](middleware-directory.html) directory listing middleware
+ *  - [vhost](middleware-vhost.html) virtual host sub-domain mapping middleware
+ *  - [favicon](middleware-favicon.html) efficient favicon server (with default icon)
+ *  - [limit](middleware-limit.html) limit the bytesize of request bodies
+ *  - [profiler](middleware-profiler.html) request profiler reporting response-time, memory usage, etc
+ *  - [query](middleware-query.html) automatic querystring parser, populating `req.query`
+ *  - [errorHandler](middleware-errorHandler.html) flexible error handler
+ *
+ * Internals:
+ *
+ *  - connect [utilities](utils.html)
+ *  - node monkey [patches](patch.html)
+ *
+ */

node_modules/connect/lib/middleware/basicAuth.js

+
+/*!
+ * Connect - basicAuth
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var utils = require('../utils')
+  , unauthorized = utils.unauthorized
+  , badRequest = utils.badRequest;
+
+/**
+ * Enfore basic authentication by providing a `callback(user, pass)`,
+ * which must return `true` in order to gain access. Alternatively an async
+ * method is provided as well, invoking `callback(user, pass, callback)`. Populates
+ * `req.remoteUser`. The final alternative is simply passing username / password
+ * strings.
+ *
+ * Examples:
+ *
+ *     connect(connect.basicAuth('username', 'password'));
+ *
+ *     connect(
+ *       connect.basicAuth(function(user, pass){
+ *         return 'tj' == user & 'wahoo' == pass;
+ *       })
+ *     );
+ *
+ *     connect(
+ *       connect.basicAuth(function(user, pass, fn){
+ *         User.authenticate({ user: user, pass: pass }, fn);
+ *       })
+ *     );
+ *
+ * @param {Function|String} callback or username
+ * @param {String} realm
+ * @api public
+ */
+
+module.exports = function basicAuth(callback, realm) {
+  var username, password;
+
+  // user / pass strings
+  if ('string' == typeof callback) {
+    username = callback;
+    password = realm;
+    if ('string' != typeof password) throw new Error('password argument required');
+    realm = arguments[2];
+    callback = function(user, pass){
+      return user == username && pass == password;
+    }
+  }
+
+  realm = realm || 'Authorization Required';
+
+  return function(req, res, next) {
+    var authorization = req.headers.authorization;
+
+    if (req.remoteUser) return next();
+    if (!authorization) return unauthorized(res, realm);
+
+    var parts = authorization.split(' ')
+      , scheme = parts[0]
+      , credentials = new Buffer(parts[1], 'base64').toString().split(':');
+
+    if ('Basic' != scheme) return badRequest(res);
+
+    // async
+    if (callback.length >= 3) {
+      var pause = utils.pause(req);
+      callback(credentials[0], credentials[1], function(err, user){
+        if (err || !user)  return unauthorized(res, realm);
+        req.remoteUser = user;
+        next();
+        pause.resume();
+      });
+    // sync
+    } else {
+      if (callback(credentials[0], credentials[1])) {
+        req.remoteUser = credentials[0];
+        next();
+      } else {
+        unauthorized(res, realm);
+      }
+    }
+  }
+};
+

node_modules/connect/lib/middleware/bodyParser.js

+
+/*!
+ * Connect - bodyParser
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var qs = require('qs')
+  , formidable = require('formidable');
+
+/**
+ * Extract the mime type from the given request's
+ * _Content-Type_ header.
+ *
+ * @param  {IncomingMessage} req
+ * @return {String}
+ * @api private
+ */
+
+function mime(req) {
+  var str = req.headers['content-type'] || '';
+  return str.split(';')[0];
+}
+
+/**
+ * Parse request bodies.
+ *
+ * By default _application/json_, _application/x-www-form-urlencoded_,
+ * and _multipart/form-data_ are supported, however you may map `connect.bodyParser.parse[contentType]`
+ * to a function receiving `(req, options, callback)`.
+ *
+ * Examples:
+ *
+ *      connect.createServer(
+ *          connect.bodyParser()
+ *        , function(req, res) {
+ *          res.end('viewing user ' + req.body.user.name);
+ *        }
+ *      );
+ *
+ *      $ curl -d 'user[name]=tj' http://localhost/
+ *      $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://localhost/
+ *
+ * Multipart req.files:
+ *
+ *   As a security measure files are stored in a separate object, stored
+ *   as `req.files`. This prevents attacks that may potentially alter
+ *   filenames, and depending on the application gain access to restricted files.
+ *
+ * Multipart configuration:
+ *
+ *  The `options` passed are provided to each parser function.
+ *  The _multipart/form-data_ parser merges these with formidable's
+ *  IncomingForm object, allowing you to tweak the upload directory,
+ *  size limits, etc. For example you may wish to retain the file extension
+ *  and change the upload directory:
+ *
+ *      server.use(bodyParser({ uploadDir: '/www/mysite.com/uploads' }));
+ *
+ *  View [node-formidable](https://github.com/felixge/node-formidable) for more information.
+ *
+ *  If you wish to use formidable directly within your app, and do not
+ *  desire this behaviour for multipart requests simply remove the
+ *  parser: 
+ *
+ *     delete connect.bodyParser.parse['multipart/form-data'];
+ *
+ *  Or
+ *
+ *     delete express.bodyParser.parse['multipart/form-data'];
+ *
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+exports = module.exports = function bodyParser(options){
+  options = options || {};
+  return function bodyParser(req, res, next) {
+    if (req.body) return next();
+    req.body = {};
+
+    if ('GET' == req.method || 'HEAD' == req.method) return next();
+    var parser = exports.parse[mime(req)];
+    if (parser) {
+      parser(req, options, next);
+    } else {
+      next();
+    }
+  }
+};
+
+/**
+ * Parsers.
+ */
+
+exports.parse = {};
+
+/**
+ * Parse application/x-www-form-urlencoded.
+ */
+
+exports.parse['application/x-www-form-urlencoded'] = function(req, options, fn){
+  var buf = '';
+  req.setEncoding('utf8');
+  req.on('data', function(chunk){ buf += chunk });
+  req.on('end', function(){
+    try {
+      req.body = buf.length
+        ? qs.parse(buf)
+        : {};
+      fn();
+    } catch (err){
+      fn(err);
+    }
+  });
+};
+
+/**
+ * Parse application/json.
+ */
+
+exports.parse['application/json'] = function(req, options, fn){
+  var buf = '';
+  req.setEncoding('utf8');
+  req.on('data', function(chunk){ buf += chunk });
+  req.on('end', function(){
+    try {
+      req.body = buf.length
+        ? JSON.parse(buf)
+        : {};
+      fn();
+    } catch (err){
+      fn(err);
+    }
+  });
+};
+
+/**
+ * Parse multipart/form-data.
+ *
+ * TODO: make multiple support optional
+ * TODO: revisit "error" flag if it's a formidable bug
+ */
+
+exports.parse['multipart/form-data'] = function(req, options, fn){
+  var form = new formidable.IncomingForm
+    , data = {}
+    , files = {}
+    , done;
+
+  Object.keys(options).forEach(function(key){
+    form[key] = options[key];
+  });
+
+  function ondata(name, val, data){
+    if (Array.isArray(data[name])) {
+      data[name].push(val);
+    } else if (data[name]) {
+      data[name] = [data[name], val];
+    } else {
+      data[name] = val;
+    }
+  }
+
+  form.on('field', function(name, val){
+    ondata(name, val, data);
+  });
+
+  form.on('file', function(name, val){
+    ondata(name, val, files);
+  });
+
+  form.on('error', function(err){
+    fn(err);
+    done = true;
+  });
+
+  form.on('end', function(){
+    if (done) return;
+    try {
+      req.body = qs.parse(data);
+      req.files = qs.parse(files);
+      fn();
+    } catch (err) {
+      fn(err);
+    }
+  });
+
+  form.parse(req);
+};

node_modules/connect/lib/middleware/compiler.js

+
+/*!
+ * Connect - compiler
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+  , path = require('path')
+  , parse = require('url').parse;
+
+/**
+ * Require cache.
+ */
+
+var cache = {};
+
+/**
+ * Setup compiler.
+ *
+ * Options:
+ *
+ *   - `src`     Source directory, defaults to **CWD**.
+ *   - `dest`    Destination directory, defaults `src`.
+ *   - `enable`  Array of enabled compilers.
+ *
+ * Compilers:
+ *
+ *   - `sass`   Compiles sass to css
+ *   - `less`   Compiles less to css
+ *   - `coffeescript`   Compiles coffee to js
+ *
+ * @param {Object} options
+ * @api public
+ */
+
+exports = module.exports = function compiler(options){
+  options = options || {};
+
+  var srcDir = options.src || process.cwd()
+    , destDir = options.dest || srcDir
+    , enable = options.enable;
+
+  if (!enable || enable.length === 0) {
+    throw new Error('compiler\'s "enable" option is not set, nothing will be compiled.');
+  }
+
+  return function compiler(req, res, next){
+    if ('GET' != req.method) return next();
+    var pathname = parse(req.url).pathname;
+    for (var i = 0, len = enable.length; i < len; ++i) {
+      var name = enable[i]
+        , compiler = compilers[name];
+      if (compiler.match.test(pathname)) {
+        var src = (srcDir + pathname).replace(compiler.match, compiler.ext)
+          , dest = destDir + pathname;
+
+        // Compare mtimes
+        fs.stat(src, function(err, srcStats){
+          if (err) {
+            if ('ENOENT' == err.code) {
+              next();
+            } else {
+              next(err);
+            }
+          } else {
+            fs.stat(dest, function(err, destStats){
+              if (err) {
+                // Oh snap! it does not exist, compile it
+                if ('ENOENT' == err.code) {
+                  compile();
+                } else {
+                  next(err);
+                }
+              } else {
+                // Source has changed, compile it
+                if (srcStats.mtime > destStats.mtime) {
+                  compile();
+                } else {
+                  // Defer file serving
+                  next();
+                }
+              }
+            });
+          }
+        });
+
+        // Compile to the destination
+        function compile() {
+          fs.readFile(src, 'utf8', function(err, str){
+            if (err) {
+              next(err);
+            } else {
+              compiler.compile(str, function(err, str){
+                if (err) {
+                  next(err);
+                } else {
+                  fs.writeFile(dest, str, 'utf8', function(err){
+                    next(err);
+                  });
+                }
+              });
+            }
+          });
+        }
+        return;
+      }
+    }
+    next();
+  };
+};
+
+/**
+ * Bundled compilers:
+ *
+ *  - [sass](http://github.com/visionmedia/sass.js) to _css_
+ *  - [less](http://github.com/cloudhead/less.js) to _css_
+ *  - [coffee](http://github.com/jashkenas/coffee-script) to _js_
+ */
+
+var compilers = exports.compilers = {
+  sass: {
+    match: /\.css$/,
+    ext: '.sass',
+    compile: function(str, fn){
+      var sass = cache.sass || (cache.sass = require('sass'));
+      try {
+        fn(null, sass.render(str));
+      } catch (err) {
+        fn(err);
+      }
+    }
+  },
+  less: {
+    match: /\.css$/,
+    ext: '.less',
+    compile: function(str, fn){
+      var less = cache.less || (cache.less = require('less'));
+      try {
+        less.render(str, fn);
+      } catch (err) {
+        fn(err);
+      }
+    }
+  },
+  coffeescript: {
+    match: /\.js$/,
+    ext: '.coffee',
+    compile: function(str, fn){
+      var coffee = cache.coffee || (cache.coffee = require('coffee-script'));
+      try {
+        fn(null, coffee.compile(str));
+      } catch (err) {
+        fn(err);
+      }
+    }
+  }
+};

node_modules/connect/lib/middleware/cookieParser.js

+
+/*!
+ * Connect - cookieParser
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var utils = require('./../utils');
+
+/**
+ * Parse _Cookie_ header and populate `req.cookies`
+ * with an object keyed by the cookie names.
+ *
+ * Examples:
+ *
+ *     connect.createServer(
+ *         connect.cookieParser()
+ *       , function(req, res, next){
+ *         res.end(JSON.stringify(req.cookies));
+ *       }
+ *     );
+ *
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function cookieParser(){
+  return function cookieParser(req, res, next) {
+    var cookie = req.headers.cookie;
+    if (req.cookies) return next();
+    req.cookies = {};
+    if (cookie) {
+      try {
+        req.cookies = utils.parseCookie(cookie);
+      } catch (err) {
+        return next(err);
+      }
+    }
+    next();
+  };
+};

node_modules/connect/lib/middleware/csrf.js

+
+/*!
+ * Connect - csrf
+ * Copyright(c) 2011 Sencha Inc.
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var utils = require('../utils')
+  , crypto = require('crypto');
+
+/**
+ * CRSF protection middleware.
+ *
+ * By default this middleware generates a token named "_csrf"
+ * which should be added to requests which mutate
+ * state, within a hidden form field, query-string etc. This
+ * token is validated against the visitor's `req.session._csrf`
+ * property which is re-generated per request.
+ *
+ * The default `value` function checks `req.body` generated
+ * by the `bodyParser()` middleware, `req.query` generated
+ * by `query()`, and the "X-CSRF-Token" header field.
+ *
+ * This middleware requires session support, thus should be added
+ * somewhere _below_ `session()` and `cookieParser()`.
+ *
+ * Examples:
+ *
+ *      var form = '\n\
+ *        <form action="/" method="post">\n\
+ *          <input type="hidden" name="_csrf" value="{token}" />\n\
+ *          <input type="text" name="user[name]" value="{user}" />\n\
+ *          <input type="password" name="user[pass]" />\n\
+ *          <input type="submit" value="Login" />\n\
+ *        </form>\n\
+ *      '; 
+ *      
+ *      connect(
+ *          connect.cookieParser()
+ *        , connect.session({ secret: 'keyboard cat' })
+ *        , connect.bodyParser()
+ *        , connect.csrf()
+ *      
+ *        , function(req, res, next){
+ *          if ('POST' != req.method) return next();
+ *          req.session.user = req.body.user;
+ *          next();
+ *        }
+ *      
+ *        , function(req, res){
+ *          res.setHeader('Content-Type', 'text/html');
+ *          var body = form
+ *            .replace('{token}', req.session._csrf)
+ *            .replace('{user}', req.session.user && req.session.user.name || '');
+ *          res.end(body);
+ *        }
+ *      ).listen(3000);
+ *
+ * Options:
+ *
+ *    - `value` a function accepting the request, returning the token 
+ *
+ * @param {Object} options
+ * @api public
+ */
+
+module.exports = function csrf(options) {
+  var options = options || {}
+    , value = options.value || defaultValue;
+
+  return function(req, res, next){
+    // generate CSRF token
+    var token = req.session._csrf || (req.session._csrf = utils.uid(24));
+
+    // ignore GET (for now)
+    if ('GET' == req.method) return next();
+
+    // determine value
+    var val = value(req);
+
+    // check
+    if (val != token) return utils.forbidden(res);
+    
+    next();
+  }
+};
+
+/**
+ * Default value function, checking the `req.body`
+ * and `req.query` for the CSRF token.
+ *
+ * @param {IncomingMessage} req
+ * @return {String}
+ * @api private
+ */
+
+function defaultValue(req) {
+  return (req.body && req.body._csrf)
+    || (req.query && req.query._csrf)
+    || (req.headers['x-csrf-token']);
+}

node_modules/connect/lib/middleware/directory.js

+
+/*!
+ * Connect - directory
+ * Copyright(c) 2011 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+// TODO: icon / style for directories
+// TODO: arrow key navigation
+// TODO: make icons extensible
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+  , parse = require('url').parse
+  , utils = require('../utils')
+  , path = require('path')
+  , normalize = path.normalize
+  , extname = path.extname
+  , join = path.join;
+
+/**
+ * Icon cache.
+ */
+
+var cache = {};
+
+/**
+ * Serve directory listings with the given `root` path.
+ *
+ * Options:
+ *
+ *  - `hidden` display hidden (dot) files. Defaults to false.
+ *  - `icons`  display icons. Defaults to false.
+ *  - `filter` Apply this filter function to files. Defaults to false.
+ *
+ * @param {String} root
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+exports = module.exports = function directory(root, options){
+  options = options || {};
+
+  // root required
+  if (!root) throw new Error('directory() root path required');
+  var hidden = options.hidden
+    , icons = options.icons
+    , filter = options.filter
+    , root = normalize(root);
+
+  return function directory(req, res, next) {
+    var accept = req.headers.accept || 'text/plain'
+      , url = parse(req.url)
+      , dir = decodeURIComponent(url.pathname)
+      , path = normalize(join(root, dir))
+      , originalUrl = parse(req.originalUrl)
+      , originalDir = decodeURIComponent(originalUrl.pathname)
+      , showUp = path != root && path != root + '/';
+
+    // null byte(s)
+    if (~path.indexOf('\0')) return utils.badRequest(res);
+
+    // malicious path
+    if (0 != path.indexOf(root)) return utils.forbidden(res);
+
+    // check if we have a directory
+    fs.stat(path, function(err, stat){
+      if (err) return 'ENOENT' == err.code
+        ? next()
+        : next(err);
+
+      if (!stat.isDirectory()) return next();
+
+      // fetch files
+      fs.readdir(path, function(err, files){
+        if (err) return next(err);
+        if (!hidden) files = removeHidden(files);
+        if (filter) files = files.filter(filter);
+        files.sort();
+        // content-negotiation
+        for (var key in exports) {
+          if (~accept.indexOf(key) || ~accept.indexOf('*/*')) {
+            exports[key](req, res, files, next, originalDir, showUp, icons);
+            return;
+          }
+        }
+        utils.notAcceptable(res);
+      });
+    });
+  };
+};
+
+/**
+ * Respond with text/html.
+ */
+
+exports.html = function(req, res, files, next, dir, showUp, icons){
+  fs.readFile(__dirname + '/../public/directory.html', 'utf8', function(err, str){
+    if (err) return next(err);
+    fs.readFile(__dirname + '/../public/style.css', 'utf8', function(err, style){
+      if (err) return next(err);
+      if (showUp) files.unshift('..');
+      str = str
+        .replace('{style}', style)
+        .replace('{files}', html(files, dir, icons))
+        .replace('{directory}', dir)
+		.replace('{linked-path}', htmlPath(dir));
+      res.setHeader('Content-Type', 'text/html');
+      res.setHeader('Content-Length', str.length);
+      res.end(str);
+    });
+  });
+};
+
+/**
+ * Respond with application/json.
+ */
+
+exports.json = function(req, res, files){
+  files = JSON.stringify(files);
+  res.setHeader('Content-Type', 'application/json');
+  res.setHeader('Content-Length', files.length);
+  res.end(files);
+};
+
+/**
+ * Respond with text/plain.
+ */
+
+exports.plain = function(req, res, files){
+  files = files.join('\n') + '\n';
+  res.setHeader('Content-Type', 'text/plain');
+  res.setHeader('Content-Length', files.length);
+  res.end(files);
+};
+
+/**
+ * Map html `dir`, returning a linked path.
+ */
+
+function htmlPath(dir) {
+  var curr = [];
+  return dir.split('/').map(function(part){
+    curr.push(part);
+    return '<a href="' + curr.join('/') + '">' + part + '</a>';
+  }).join(' / ');
+}
+
+/**
+ * Map html `files`, returning an html unordered list.
+ */
+
+function html(files, dir, useIcons) {
+  return '<ul id="files">' + files.map(function(file){
+    var icon = ''
+      , classes = [];
+
+    if (useIcons && '..' != file) {
+      icon = icons[extname(file)] || icons.default;
+      icon = '<img src="data:image/png;base64,' + load(icon) + '" />';
+      classes.push('icon');
+    }
+
+    return '<li><a href="'
+      + join(dir, file)
+      + '" class="'
+      + classes.join(' ') + '"'
+      + ' title="' + file + '">'
+      + icon + file + '</a></li>';
+
+  }).join('\n') + '</ul>';
+}
+
+/**
+ * Load and cache the given `icon`.
+ *
+ * @param {String} icon
+ * @return {String}
+ * @api private
+ */
+
+function load(icon) {
+  if (cache[icon]) return cache[icon];
+  return cache[icon] = fs.readFileSync(__dirname + '/../public/icons/' + icon, 'base64');
+}
+
+/**
+ * Filter "hidden" `files`, aka files
+ * beginning with a `.`.
+ *
+ * @param {Array} files
+ * @return {Array}
+ * @api private
+ */
+
+function removeHidden(files) {
+  return files.filter(function(file){
+    return '.' != file[0];
+  });
+}
+
+/**
+ * Icon map.
+ */
+
+var icons = {
+    '.js': 'page_white_code_red.png'
+  , '.c': 'page_white_c.png'
+  , '.h': 'page_white_h.png'
+  , '.cc': 'page_white_cplusplus.png'
+  , '.php': 'page_white_php.png'
+  , '.rb': 'page_white_ruby.png'
+  , '.cpp': 'page_white_cplusplus.png'
+  , '.swf': 'page_white_flash.png'
+  , '.pdf': 'page_white_acrobat.png'
+  , 'default': 'page_white.png'
+};

node_modules/connect/lib/middleware/errorHandler.js

+/*!
+ * Connect - errorHandler
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var utils = require('../utils')
+  , url = require('url')
+  , fs = require('fs');
+
+/**
+ * Flexible error handler, providing (_optional_) stack traces
+ * and error message responses for requests accepting text, html,
+ * or json.
+ *
+ * Options:
+ *
+ *   - `showStack`, `stack` respond with both the error message and stack trace. Defaults to `false`
+ *   - `showMessage`, `message`, respond with the exception message only. Defaults to `false`
+ *   - `dumpExceptions`, `dump`, dump exceptions to stderr (without terminating the process). Defaults to `false`
+ *
+ * Text:
+ *
+ *   By default, and when _text/plain_ is accepted a simple stack trace
+ *   or error message will be returned.
+ *
+ * JSON:
+ *
+ *   When _application/json_ is accepted, connect will respond with
+ *   an object in the form of `{ "error": error }`. 
+ *
+ * HTML:
+ *
+ *   When accepted connect will output a nice html stack trace.
+ *
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+exports = module.exports = function errorHandler(options){
+  options = options || {};
+
+  // defaults
+  var showStack = options.showStack || options.stack
+    , showMessage = options.showMessage || options.message
+    , dumpExceptions = options.dumpExceptions || options.dump
+    , formatUrl = options.formatUrl;
+
+  return function errorHandler(err, req, res, next){
+    res.statusCode = 500;
+    if (dumpExceptions) console.error(err.stack);
+    if (showStack) {
+      var accept = req.headers.accept || '';
+      // html
+      if (~accept.indexOf('html')) {
+        fs.readFile(__dirname + '/../public/style.css', 'utf8', function(e, style){
+          fs.readFile(__dirname + '/../public/error.html', 'utf8', function(e, html){
+            var stack = (err.stack || '')
+              .split('\n').slice(1)
+              .map(function(v){ return '<li>' + v + '</li>'; }).join('');
+              html = html
+                .replace('{style}', style)
+                .replace('{stack}', stack)
+                .replace('{title}', exports.title)
+                .replace(/\{error\}/g, utils.escape(err.toString()));
+              res.setHeader('Content-Type', 'text/html');
+              res.end(html);
+          });
+        });
+      // json
+      } else if (~accept.indexOf('json')) {
+        var json = JSON.stringify({ error: err });
+        res.setHeader('Content-Type', 'application/json');
+        res.end(json);
+      // plain text
+      } else {
+        res.writeHead(500, { 'Content-Type': 'text/plain' });
+        res.end(err.stack);
+      }
+    } else {
+      var body = showMessage
+        ? err.toString()
+        : 'Internal Server Error';
+      res.setHeader('Content-Type', 'text/plain');
+      res.end(body);
+    }
+  };
+};
+
+/**
+ * Template title.
+ */
+
+exports.title = 'Connect';

node_modules/connect/lib/middleware/favicon.js

+
+/*!
+ * Connect - favicon
+ * Copyright(c) 2010 Sencha Inc.
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+  , utils = require('../utils');
+
+/**
+ * Favicon cache.
+ */
+
+var icon;
+
+/**
+ * By default serves the connect favicon, or the favicon
+ * located by the given `path`.
+ *
+ * Options:
+ *
+ *   - `maxAge`  cache-control max-age directive, defaulting to 1 day
+ *
+ * Examples:
+ *
+ *     connect.createServer(
+ *       connect.favicon()    
+ *     );
+ *
+ *     connect.createServer(
+ *       connect.favicon(__dirname + '/public/favicon.ico')    
+ *     );
+ *
+ * @param {String} path
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function favicon(path, options){
+  var options = options || {}
+    , path = path || __dirname + '/../public/favicon.ico'
+    , maxAge = options.maxAge || 86400000;
+
+  return function favicon(req, res, next){
+    if ('/favicon.ico' == req.url) {
+      if (icon) {
+        res.writeHead(200, icon.headers);
+        res.end(icon.body);
+      } else {
+        fs.readFile(path, function(err, buf){
+          if (err) return next(err);
+          icon = {
+            headers: {
+                'Content-Type': 'image/x-icon'
+              , 'Content-Length': buf.length
+              , 'ETag': '"' + utils.md5(buf) + '"'
+              , 'Cache-Control': 'public, max-age=' + (maxAge / 1000)
+            },
+            body: buf
+          };
+          res.writeHead(200, icon.headers);
+          res.end(icon.body);
+        });
+      }
+    } else {
+      next();
+    }
+  };
+};

node_modules/connect/lib/middleware/limit.js

+
+/*!
+ * Connect - limit
+ * Copyright(c) 2011 TJ Holowaychuk
+ * MIT Licensed
+ */
+
+/**
+ * Limit request bodies to the given size in `bytes`.
+ *
+ * A string representation of the bytesize may also be passed,
+ * for example "5mb", "200kb", "1gb", etc.
+ *
+ * Examples:
+ *
+ *     var server = connect(
+ *       connect.limit('5.5mb')
+ *     ).listen(3000);
+ *
+ * TODO: pause EV_READ
+ *
+ * @param {Number|String} bytes
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function limit(bytes){
+  if ('string' == typeof bytes) bytes = parse(bytes);
+  if ('number' != typeof bytes) throw new Error('limit() bytes required');
+  return function limit(req, res, next){
+    var received = 0
+      , len = req.headers['content-length']
+        ? parseInt(req.headers['content-length'], 10)
+        : null;
+
+    // deny the request
+    function deny() {
+      req.destroy();
+    }
+
+    // self-awareness
+    if (req._limit) return next();
+    req._limit = true;
+
+    // limit by content-length
+    if (len && len > bytes) {
+      res.statusCode = 413;
+      res.end('Request Entity Too Large');
+      return;
+    }
+
+    // limit
+    req.on('data', function(chunk){
+      received += chunk.length;
+      if (received > bytes) deny();
+    });
+
+    next();
+  };
+};
+
+/**
+ * Parse byte `size` string.
+ *
+ * @param {String} size
+ * @return {Number}
+ * @api private
+ */
+
+function parse(size) {
+  var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb)$/)
+    , n = parseFloat(parts[1])
+    , type = parts[2];
+
+  var map = {
+      kb: 1024
+    , mb: 1024 * 1024
+    , gb: 1024 * 1024 * 1024
+  };
+
+  return map[type] * n;
+}

node_modules/connect/lib/middleware/logger.js

+
+/*!