如何为所有或单个响应捕获服务器端环回 return callback() 函数?

How to catch server side loopback return callback() function for all or individual responses?

在 Node.js 使用 LoopBack 框架时,我想捕获所有发送给客户端的响应。

 return cb(null, {
             success: true,
             msg: "Customer successfully fatch",
             data: {}
     });

我想在所有处理后将所有响应转换为语言转换。

我可以为此使用任何节点模块还是有任何其他方法来实现它?

您应该使用 Remote Hooks 挂接 before/after API 个电话。

您正在查看的具体是afterRemote()

示例:

Car.afterRemote('revEngine', function(context, remoteMethodOutput, next) {
    console.log('Turning off the engine, removing the key.');
    // context.res is your Express Response object.
    next();
});