在 Loopback.io 远程方法中访问入站 HTTP Headers

Access Inbound HTTP Headers in Loopback.io Remote Method

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

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 headers 以验证它们。有人可以帮忙吗

对于远程方法 accepts 使用 -

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

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

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