1

我想在我的 express 3 路由中使用 http.Server.connections?是不是再也没有办法获得了?

我应该只是 app.set('server', server);

express.createServer() 已弃用,express 应用程序不再继承自 http.Server

var app = express(),
server = http.createServer(app);
server.listen(8080);
...
module.exports = function (app) {

    app.get('/connections', function (req, res) {
        res.send({
            connections: app.connections 
            // app != http.Server in express 3
        });
    });

};
4

2 回答 2

3

而不是app.connections你需要发送server.connections,因为你已经使用过:

server = http.createServer(app);

所以你的代码变成:

app.get('/connections', function (req, res) {
    res.send({
        connections: server.connections 
    });
});
于 2012-11-06T11:09:18.500 回答
0
app.locals.connections = app.connections

然后在您的回复中:

res.send({ connections: res.locals.connections});
于 2012-10-10T22:33:32.637 回答