使用来自express.io路由的API

时间:2016-03-16 08:50:45

标签: angularjs node.js express socket.io express.io

我不确定如何将NodeJS API与express.io结合使用 有一个API定义:

app.get('/api', function(req, res) {
    connection.query("select * from table") , function (error, results) {       
        if(error) {
            throw error;
        }
        else { 
            res.end(JSON.stringify(results));
        }
    });
});

如何转换API以与express.io一起使用? 我尝试使用app.io.route,但这显然是错误的:

app.io.route('/api', function(req) {
    connection.query("select * from table", function (error, results) {     
        if(error) {
            throw error;
        }
        else { 
            req.end(JSON.stringify(results));
        }
    });
});

0 个答案:

没有答案