Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从环回中删除路由_Javascript_Node.js_Loopbackjs_Strongloop - Fatal编程技术网

Javascript 从环回中删除路由

Javascript 从环回中删除路由,javascript,node.js,loopbackjs,strongloop,Javascript,Node.js,Loopbackjs,Strongloop,我开始使用loopback来创建我的API,我面临一个问题:有没有办法从loopback中删除路由 假设我有一个管理员模型,我想添加一个自定义路由(比如Admin/login),在这个路由上我发送用户名和密码,如果可以的话,它会返回“ok”。但我不想所有这些路线都像计数,改变流,等等 我怎样才能移除它们?我一直在谷歌上搜索,但没有与我的问题相对应的答案 提前感谢您的回复 在github上打开了一个旧版本: 以下是@dancingshell的详细答案: use strict'; const r

我开始使用loopback来创建我的API,我面临一个问题:有没有办法从loopback中删除路由

假设我有一个管理员模型,我想添加一个自定义路由(比如Admin/login),在这个路由上我发送用户名和密码,如果可以的话,它会返回“ok”。但我不想所有这些路线都像计数,改变流,等等

我怎样才能移除它们?我一直在谷歌上搜索,但没有与我的问题相对应的答案


提前感谢您的回复

在github上打开了一个旧版本:

以下是@dancingshell的详细答案:

use strict';
const
  relationMethodPrefixes = [
    'prototype.__findById__',
    'prototype.__destroyById__',
    'prototype.__updateById__',
    'prototype.__exists__',
    'prototype.__link__',
    'prototype.__get__',
    'prototype.__create__',
    'prototype.__update__',
    'prototype.__destroy__',
    'prototype.__unlink__',
    'prototype.__count__',
    'prototype.__delete__'
  ];

function reportDisabledMethod( model, methods ) {
  const joinedMethods = methods.join( ', ' );

  if ( methods.length ) {
    console.log( '\nRemote methods hidden for', model.sharedClass.name, ':', joinedMethods, '\n' );
  }
}

module.exports = {
  disableAllExcept( model, methodsToExpose ) {
    const
      excludedMethods = methodsToExpose || [];
    var hiddenMethods = [];

    if ( model && model.sharedClass ) {
      model.sharedClass.methods().forEach( disableMethod );
      Object.keys( model.definition.settings.relations ).forEach( disableRelatedMethods );
      reportDisabledMethod( model, hiddenMethods );
    }
    function disableRelatedMethods( relation ) {
      relationMethodPrefixes.forEach( function( prefix ) {
        var methodName = prefix + relation;

        disableMethod({ name: methodName });
      });
    }
    function disableMethod( method ) {
      var methodName = method.name;

      if ( excludedMethods.indexOf( methodName ) < 0 ) {
        model.disableRemoteMethodByName( methodName );
        hiddenMethods.push( methodName );
      }
    }
  },
  /**
   * Options for methodsToDisable:
   * create, upsert, replaceOrCreate, upsertWithWhere, exists, findById, replaceById,
   * find, findOne, updateAll, deleteById, count, updateAttributes, createChangeStream
   * -- can also specify related method using prefixes listed above
   * and the related model name ex for Account: (prototype.__updateById__followers, prototype.__create__tags)
   * @param model
   * @param methodsToDisable array
   */
  disableOnlyTheseMethods( model, methodsToDisable ) {
    methodsToDisable.forEach( function( method ) {
      model.disableRemoteMethodByName( method );
    });
    reportDisabledMethod( model, methodsToDisable );
  }
};
使用strict';
常数
relationMethodPrefixes=[
“原型。”,
“原型._;销毁BYID__;”,
“prototype.\uuuu updateById\uuuuuu”,
“原型存在”,
“原型链接”,
“原型.___;,
“原型。创建”,
'原型。_更新_',
“原型.____;破坏__;”,
“原型._;取消链接_;”,
“原型.__计数_;”,
'原型。_删除_;'
];
函数reportDisabledMethod(模型、方法){
const joinedMethods=methods.join(',');
如果(方法长度){
console.log(“\n为”“model.sharedClass.name”“隐藏的远程方法”“:”,joinedMethods”“\n');
}
}
module.exports={
disableAllExcept(模型、方法公开){
常数
excludedMethods=methodsToExpose | |[];
var hiddenMethods=[];
if(model&&model.sharedClass){
model.sharedClass.methods().forEach(disableMethod);
key(model.definition.settings.relations).forEach(disableRelatedMethods);
reportDisabledMethod(模型、隐藏方法);
}
函数禁用RelatedMethods(关系){
relationMethodPrefixes.forEach(函数(前缀){
var methodName=前缀+关系;
禁用方法({name:methodName});
});
}
功能失效方法(方法){
var methodName=method.name;
if(排除方法索引of(方法名)<0){
model.disableRemoteMethodByName(methodName);
hiddenMethods.push(methodName);
}
}
},
/**
*方法选项禁用:
*create、upsert、replaceOrCreate、upsertWithWhere、exists、findById、replaceById、,
*查找、findOne、updateAll、deleteById、计数、updateAttributes、createChangeStream
*--还可以使用上面列出的前缀指定相关方法
*以及帐户的相关模型名称ex:(prototype.\uuuuUpdateById\uuuuuu followers,prototype.\uuuuuu create\uuuuu标记)
*@param模型
*@param methodsToDisable数组
*/
仅禁用这些方法(模型、方法禁用){
methodsToDisable.forEach(函数(方法){
model.disableRemoteMethodByName(方法);
});
reportDisabledMethod(模型、方法禁用);
}
};
但我建议使用@c3s4r制作的定制mixin插件: