我使用express-ws在我的服務器和客戶端瀏覽器之間發現了可靠的Websocket連接,從而發現了我的web服務器的示例代碼。代碼將開始在3000端口監聽websocket連接。next()調用nodejs中的express-ws模塊
var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
app.use(function (req, res, next) {
console.log('middleware');
req.testing = 'testing';
return next();
});
app.get('/', function(req, res, next){
console.log('get route', req.testing);
res.end();
});
app.ws('/', function(ws, req) {
ws.on('message', function(msg) {
console.log(msg);
});
console.log('socket', req.testing);
});
server.listen(3000);
express-websocket中next()API的用法是什麼?