H_P
H_P

Reputation: 15

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

In Node.js using the LoopBack framework, I want to catch all responses that I have send to the client.

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

I want to convert all response for language conversion after all processing.

Can I use any node module for that or is there any other way to implement it?

Upvotes: 1

Views: 195

Answers (1)

Ajk_P
Ajk_P

Reputation: 1884

You should use Remote Hooks to hook before/after API calls.

The specific one you are looking at is afterRemote()

Example:

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

Upvotes: 1

Related Questions