I am testing Loopback for an API that will talk to Ember.
Ember requires JSON to be contained in "keys", for example. for account:
{ account: { domain: 'domain.com', subdomain: 'test', title: 'test.domain.com', id: 1 } }
I found some tips in the google group on how to change the answer so that Ember gets it using hook.
eg. on my /account.js models:
module.exports = function(Account) { Account.afterRemote('**', function (ctx, account, next) { if(ctx.result) { if(Array.isArray(ctx.result)) { ctx.res.body = { 'accounts': account }; } else { ctx.res.body = { 'account': account }; } } console.log(ctx.res.body); next(); }); };
I see that the answer is the same as in the console. However, the JSON output on localhost: 3000 / api / accounts does not show the modified JSON object.
What is the correct way to modify JSON responses / requests in Loopback?
Ideal in the general case, so it can be applied to all models.
source share