从Union获取simple example,我想知道可以将通常放在app.configure中的配置代码放在哪里,比如passport.js
app.configure(function() {
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
});有什么想法吗?服务器和路由器不接受use()。
发布于 2012-03-20 04:52:10
Union似乎使用before集合来实现这一点:
var server = union.createServer({
before: [
connect.session({ secret: 'keyboard cat' }), // for `passport.session()`
passport.initialize(),
passport.session(),
// etc.
]
});@option before {Array}
The `before` value is an array of middlewares, which are used to route and serve incoming
requests. For instance, in the example, `favicon` is a middleware which handles requests
for `/favicon.ico`.发布于 2012-05-04 10:40:49
正如前面提到的,Union支持通过before属性连接中间件。但是,union不处理应用程序配置;flatiron处理。然而,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());我还没有试过运行这个例子(我相信这里有更多的细节),但希望这能给你一个想法。
发布于 2012-08-28 20:32:43
我刚刚构建了一个包装器来集成Passport.js和Flatiron.js。
https://npmjs.org/package/flatiron-passport
https://github.com/travist/flatiron-passport
请阅读README.md,了解如何使用它并将其应用于您的应用程序。
我已经在LocalStrategy上测试过了,但它应该适用于其他策略。
否则请让我知道。
https://stackoverflow.com/questions/9777355
复制相似问题