联盟支持通过before
属性连接的中间件,如前面其他人所说。但是,union不处理应用程序配置;熨斗做。但是,api与express有很大不同。
例如,配置一个应用程序可能是这个样子:
var path = require('path'),
flatiron = require('flatiron'),
app = flatiron.app,
plugins = flatiron.plugins,
connect = require('connect'), // most connect middlewares work with flatiron ootb
passport = require('passport');
// Use flatiron's http plugin (not the same as a middleware!)
app.use(plugins.http);
// configuration consists of key/value pairs, not of function blocks associated with
// certain "environments".
// Here's *a* way you can handle environment-based configs; there are others!
app.config.file(path.resolve(
__dirname,
'config',
(process.env.NODE_ENV || 'config') + '.json'
));
// Use our config to set the secret
app.http.before.push(connect.session({
secret: app.config.get('secret') || 'keyboard cat' //default
}))
app.http.before.push(passport.initialize());
app.http.before.push(passport.session());
我还没有试过运行这个例子(我敢肯定有很多细节),但希望这给你的想法。
'之前'与每个请求调用。应用程序加载时,仅配置一次app.configure。所以这是不一样的(并产生大量的开销)。 – Patrick 2012-03-20 09:39:18
@Patrick这就是[Connect](http://www.senchalabs.org/connect/)基于中间件的工作原理 - 它们必须能够响应每个请求,或者将它传递到下一个中间件。 ['app.configure'](http://expressjs.com/guide.html#configuration)设置相同的场景;它只是选择一系列'app.use'调用(可以选择将它们连接到各种部署模式),而不是一个单独的,常量的'before'数组。这就是为什么它可以帮助挑剔你使用的中间件 - 每一个都会不断增加一些开销。 – 2012-03-20 16:53:19
嗯,好的。我习惯于Express中的场景。我只是想知道,因为护照不起作用,我不明白为什么。 – Patrick 2012-03-20 18:07:15