我想在我的 Express 3 路线中使用 http.Server.connections 吗? 难道就没有办法再获取了吗
我应该 app.set('服务器', 服务器);
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
});
});
};
您需要发送
app.connections
,而不是 server.connections
,因为您已经使用了:
server = http.createServer(app);
所以你的代码变成:
app.get('/connections', function (req, res) {
res.send({
connections: server.connections
});
});
app.locals.connections = app.connections
然后在您的回复中:
res.send({ connections: res.locals.connections});