From 9a631aa1244f7c320d7a8e648558bf909f5a5cfb Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Thu, 24 Jun 2010 20:37:58 -0700 Subject: [PATCH] Fixed more docs --- lib/connect/middleware/router.js | 30 ++++++++++++------------ lib/connect/middleware/session.js | 5 +++- lib/connect/middleware/staticProvider.js | 23 ++++++++++++++---- lib/connect/middleware/vhost.js | 18 +++++++++++++- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/lib/connect/middleware/router.js b/lib/connect/middleware/router.js index 92f854d3e..7aa0eb60d 100644 --- a/lib/connect/middleware/router.js +++ b/lib/connect/middleware/router.js @@ -12,10 +12,22 @@ var parse = require('url').parse; /** - * Setup routes. + * Provides Sinatra and Express like routing capabilities. + * + * Examples: + * + * connect.router(function(app){ + * app.get('/user/:id', function(req, res, params){ + * // populates params.id + * }); + * }) + * + * @param {Function} fn + * @return {Function} + * @api public */ -module.exports = function setup(fn) { +module.exports = function(fn){ var routes; if (fn) { @@ -30,14 +42,6 @@ module.exports = function setup(fn) { throw new Error('router provider requires a callback function'); } - /** - * Return a routing function. - * - * @param {String} name - * @return {Function} - * @api private - */ - function method(name) { var self = this, localRoutes = routes[name] = routes[name] || []; @@ -51,11 +55,7 @@ module.exports = function setup(fn) { }; } - - /** - * Attempt to match and call a route. - */ - return function handle(req, res, next) { + return function(req, res, next){ var self = this; process.nextTick(function(){ var route; diff --git a/lib/connect/middleware/session.js b/lib/connect/middleware/session.js index d185657d3..85c936b05 100644 --- a/lib/connect/middleware/session.js +++ b/lib/connect/middleware/session.js @@ -20,6 +20,9 @@ var MemoryStore = require('./session/memory').MemoryStore, * - `store` Session store instance * - `fingerprint` Custom fingerprint hashing function * + * @param {Object} options + * @return {Function} + * @api public */ module.exports = function(options){ @@ -35,7 +38,7 @@ module.exports = function(options){ + (req.headers['user-agent'] || ''); }; - return function handle(req, res, next){ + return function(req, res, next){ // Expose store req.sessionStore = store; diff --git a/lib/connect/middleware/staticProvider.js b/lib/connect/middleware/staticProvider.js index d3f4dea0b..1b9fd97d9 100644 --- a/lib/connect/middleware/staticProvider.js +++ b/lib/connect/middleware/staticProvider.js @@ -1,26 +1,41 @@ + /*! * Ext JS Connect * Copyright(c) 2010 Ext JS, Inc. * MIT Licensed */ +/** + * Module dependencies. + */ + var fs = require('fs'), Url = require('url'), Buffer = require('buffer').Buffer, Path = require('path'), utils = require('./../utils'); -var lifetime = 1000 * 60 * 60; // 1 hour browser cache lifetime +/** + * Browser cache lifetime of one hour. + * + * @type Number + */ + +var lifetime = 1000 * 60 * 60; /** - * Setup static file server. + * Static file server. * * Options: * - * - root Root path from which to serve static files. + * - `root` Root path from which to serve static files. + * + * @param {String} root + * @return {Function} + * @api public */ -module.exports = function setup(root) { +module.exports = function(root){ root = process.connectEnv.staticRoot || root || process.cwd(); return function handle(req, res, next) { var url = Url.parse(req.url); diff --git a/lib/connect/middleware/vhost.js b/lib/connect/middleware/vhost.js index f3380d039..0cf0a1aa6 100644 --- a/lib/connect/middleware/vhost.js +++ b/lib/connect/middleware/vhost.js @@ -6,7 +6,23 @@ */ /** - * Setup vhost. + * Setup vhost for the given `hostname` and `server`. + * + * Examples: + * + * connect.createServer( + * connect.vhost('foo.com', + * connect.createServer(...middleware...) + * ), + * connect.vhost('bar.com', + * connect.createServer(...middleware...) + * ) + * ); + * + * @param {String} hostname + * @param {Server} server + * @return {Function} + * @api public */ module.exports = function(hostname, server){