Enabling replaceById enables PUT, PATCH and POST request url

9 views
Skip to first unread message

ashcs...@gmail.com

unread,
Oct 6, 2017, 5:56:09 AM10/6/17
to LoopbackJS
Hi,

I want to disable remote methods except a few. I am using the following method to disableRemoteMethods.



    disableAllMethodsBut
: function(model, methodsToExpose) {
       
if(model && model.sharedClass)
       
{
            methodsToExpose
= methodsToExpose || [];


           
var modelName = model.sharedClass.name;
           
var methods = model.sharedClass.methods();
           
var relationMethods = [];
           
var hiddenMethods = [];


           
try
           
{
               
Object.keys(model.definition.settings.relations).forEach(function(relation)
               
{
                    relationMethods
.push({ name: 'prototype.__findById__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__destroyById__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__updateById__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__exists__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__link__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__get__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__create__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__update__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__destroy__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__unlink__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__count__' + relation, isStatic: false });
                    relationMethods
.push({ name: 'prototype.__delete__' + relation, isStatic: false });
               
});
           
} catch(err) {}


            methods
.concat(relationMethods).forEach(function(method)
           
{
               
var methodName = method.name;
               
if(methodsToExpose.indexOf(methodName) < 0)
               
{
                    model
.disableRemoteMethodByName(methodName, method.isStatic);
               
}
           
});


           
if(hiddenMethods.length > 0)
           
{
                console
.log('\nRemote mehtods hidden for', modelName, ':', hiddenMethods.join(', '), '\n');
           
}


       
}
   
}

I have also updated this method to use disableRemoteMethodByName(). To disable methods selectively I use the following:

    utils.disableAllMethodsBut(
       
Customer,
       
['replaceById', 'deleteById', 'logout']
   
);

But activating replaceById enables PUT, PATCH and POST urls as well:

PUT /customers/{id}



I want to enable PUT request only and disable others. How do I achieve that ?

Thanks in advance !!
Reply all
Reply to author
Forward
0 new messages