Using everyauth with restify

非 Y 不嫁゛ 提交于 2019-12-03 16:30:19

The issue you are having is restify does not and current will not have a middleware layer.

The below is from the author of restify

I've thought about this quite a bit, and the thing that worries me here is signing up for compatibility with connect evermore. I don't have control or input over what they decide to do. This seems more in the vein of "if it works, great".

I'm going to close this out with a "won't fix" for now :\

https://github.com/mcavage/node-restify/issues/89

What you can do is use connect and add the restify server on top of that, then you can use connect to manage your middleware like everyauth.

Here is a great sample of this, I have it working great on my system as-is.

// 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

Then you can add everyauth to connect as per the documents.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!