How to use connect router without connect http server?
I have a function:
function foo(request, response, next)
{
...
}
And I want to use the router from 'connect' npm library to route the request. However, I could only find in the documentation how to attach the router to the built-in HTTP server of connect. I want to do something like this:
var connect = require('connect')
function foo(request, response, next)
{
connect.middleware.router(request, response, next, function (app)
{
app.get('/', ...)
app.get('/openid/verify', ...)开发者_高级运维
...
})
}
The question is: how do I pass request, response and next to connect router?
You should be able to do the following:
var connect = require('connect');
var router = connect.middleware.router(function (app) {
app.get('/', ...)
app.get('/openid/verify', ...)
});
function handleRequest(req, res, next) {
router(req, res, next);
}
精彩评论