Node.js Rest API调用

问题描述:

我有一个后期API请求,我需要帮助。我想在Post请求后调用一个函数,但函数没有被执行。Node.js Rest API调用

var restful = require('node-restful'); 
module.exports = function(app, route) { 
    // Setup the controller for REST. 
    var rest = restful.model(
    'post', 
    app.models.post 
).methods(['get', 'put', 'post', 'delete']); 

    // Register this endpoint with the application. 
    rest.register(app, route); 
    rest.after('post', send_me_email) 

    function send_me_email(req, res, next) { 
    server.send({ 
    text: "i hope this works", 
    from: "****@******.com", 
    to:  "******@gmail.com", 
    subject: "testing emailjs" 
    }, 
    function(err, message) { 
     console.log(err || message); 
    }) 

    console.log("HERE IS THE POST AFTER: " + req.body); 
    next(); 
    } 

    // Return middleware. 
    return function(req, res, next) { 
    next(); 
    }; 
} 

function send_me_email(req, res, next) { 
     server.send({ 
     text: "i hope this works", 
     from: "****@******.com", 
     to:  "******@gmail.com", 
     subject: "testing emailjs" 
     }, 
     function(err, message) { 
      console.log(err || message); 
     }) 

     console.log("HERE IS THE POST AFTER: " + req.body); 
     next(); 
     } 

应该

function send_me_email(req, res, next) { 
    server.send({ 
    text: "i hope this works", 
    from: "****@******.com", 
    to:  "******@gmail.com", 
    subject: "testing emailjs" 
    }, 
    function(err, message) { 
     console.log(err || message); 

     if(err) return next(err); 

     console.log("HERE IS THE POST AFTER: " + req.body); 
     next(); 

    }) 

    }