我正在尝试使用 everyauth 来处理使用restify 创建的rest api 的身份验证。
但却找不到起点。我希望做类似的事情:
var restify = require('restify');
var everyauth = require('everyauth');
var server = restify.createServer();
server.use(everyauth.middleware());
但restify不接受everyauth中间件。
我该如何设置restify和everyauth?
您遇到的问题是 Restify 没有,并且当前没有中间件层。
以下来自restify作者
我对此思考了很多,而让我担心的是注册与 connect 的兼容性。我无法控制或参与他们决定做什么。这似乎更符合“如果有效,那就太好了”的精神。
我现在要以“无法修复”来结束这个问题:\
https://github.com/mcavage/node-restify/issues/89 https://github.com/mcavage/node-restify/issues/89
你可以做的是使用 connect 并在其上添加restify服务器,然后你可以使用 connect 来管理你的中间件,就像 everyauth 一样。
这是一个很好的示例,我让它在我的系统上运行得很好。
// Restify server config here
var server = restify.createServer({
name: 'restify-test',
version: '1.0.0',
});
// ...
// Connect config here
var connectApp = connect()
.use(connect.logger())
.use(connect.bodyParser())
.use(connect.query())
.use(connect.cookieParser())
// And this is where the magic happens
.use("/api", function (req, res) {
server.server.emit('request', req, res);
});
connectApp.listen(8080);
https://gist.github.com/2140974 https://gist.github.com/2140974
然后您可以按照文档添加 everyauth 进行连接。
希望有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)