我有一个远程方法,用于放置应用程序逻辑,如下所示:

module.exports = function(Entity) {
  HcpEntity.retrieveProfile = function(body, cb) {
    process.nextTick(function() {
      //TODO: Application Logic
    }
 }
}

相应的模型JSON代码片段是:
{
    "name": "HcpEntity",
    "base": "Model",
    "properties": {},
    "methods": {
        "retrieveProfile": {
            "isStatic" : true,
            "accepts": [
                {
                    "arg": "Request",
                    "type": "object",
                    "required": true,
                    "http": {
                        "source": "body"
                    }
                }
            ],
            "returns": {
                "arg": "Response",
                "type": "object"
            },
            "http": {
                "verb": "post"
            }
        }
    }
}

我需要能够访问标记为//TODO: Application Logic的区域中的传入HTTP header ,以便对其进行验证。有人可以帮忙吗。

最佳答案

对于远程方法accepts使用-

accepts: [
    {arg: 'req', type: 'object', http: {source: 'req'}}
],

请求 header 必须在req.headers中可用。

另请:https://loopback.io/doc/en/lb3/Remote-methods.html#http-mapping-of-input-arguments

09-28 03:09