高阶函数呢?
exports.cmp = function(io) { return function(req, res){ var product_id = req.body.product_id; var bid = req.body.bid.split('b')[1]; io.sockets.emit("bidSuccess", {product_id: product_id, bid: bid}); response.json(200, {message: "Message received!"}); }};
然后
app.post('/cmp', routes.cmp(io));
作为另一种选择,有时我会将路线的格式设置为以下格式:
var routes = require('./routes/routes');routes(app, io);
然后定义
routes为
module.exports = function(app, io) { app.post('/cmp', function(req, res){ var product_id = req.body.product_id; var bid = req.body.bid.split('b')[1]; io.sockets.emit("bidSuccess", {product_id: product_id, bid: bid}); response.json(200, {message: "Message received!"}); })};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)