Created
August 27, 2011 08:48
-
-
Save Jxck/1175150 to your computer and use it in GitHub Desktop.
I want to configuration like this..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function noop(){}; | |
function para() { | |
var list = arguments; | |
return function(req, res, next) { | |
var current = 0; | |
var len = list.length; | |
for (var i = 0; i < len; ++i) { | |
var fun = list[i]; | |
fun(req, res, function() { | |
if (++current === len) { | |
next(); | |
} | |
}); | |
} | |
}; | |
}; | |
function fork(fun) { | |
return function(req, res, next) { | |
fun(req, res, noop); | |
next(); | |
}; | |
} | |
function conf(){ | |
var list = arguments; | |
var m; | |
function add(env, middle) { | |
app.configure(env, function(){ | |
app.use(middle); | |
}); | |
}; | |
for(var i in list) { | |
m = list[i]; | |
if(typeof m === 'function'){ | |
add('all', m); | |
}; | |
if(typeof m === 'object'){ | |
for(var j in m){ | |
if(typeof j === 'string' ){ | |
app.set(j, m[j]); | |
} | |
add(j, m[j]); | |
} | |
} | |
} | |
}; | |
/** | |
* Module dependencies. | |
*/ | |
var express = require('express'); | |
var app = module.exports = express.createServer(); | |
// Configuration | |
// app.configure(function(){ | |
// app.set('views', __dirname + '/views'), | |
// app.set('view engine', 'ejs'), | |
// app.use(express.bodyDecoder()); | |
// app.use(express.methodOverride()); | |
// app.use(express.cookieDecoder()); | |
// app.use(express.session({ secret: 'your secret here' })); | |
// app.use(app.router); | |
// app.use(express.staticProvider(__dirname + '/public')); | |
// }); | |
// app.configure('development', function(){ | |
// app.use(express.errorHandler({ dumpExceptions: true, showStack: true }); | |
// }); | |
// app.configure('production', function(){ | |
// app.use(express.errorHandler()); | |
// }); | |
conf( | |
{'views': __dirname + '/views'}, // set param | |
{'view engine': 'ejs'}, // set param | |
para(express.bodyDecoder(), express.cookieDecoder()), // parallel | |
para(express.methodOverride(), express.session({secret: 'asdf'})), // parallel | |
{ // each env | |
"production": express.logger(':method :url :status'), | |
"development": express.logger(':method'), | |
"test": express.logger(':status') | |
}, | |
express.staticProvider(__dirname + '/public'), // all | |
app.router, // all | |
{ // each env | |
"development": express.errorHandler({ dumpExceptions: true, showStack: true }), | |
"test": app.use(express.errorHandler()) | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment