从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()。
答案 0 :(得分:1)
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`.
答案 1 :(得分:1)
Union支持通过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());
我没有试过运行这个例子(我确定这里有更多详细信息)但希望这会给你一个想法。
答案 2 :(得分:1)
我刚刚构建了一个将Passport.js与Flatiron.js集成的包装器。
https://npmjs.org/package/flatiron-passport
https://github.com/travist/flatiron-passport
请阅读README.md,了解如何使用它并将其应用到您的应用程序中。
我在LocalStrategy上测试了它,但它应该适用于其他策略。
请让我知道。