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

时间:2017-07-21 03:50:03

标签: javascript node.js loopbackjs

我有一个远程方法,我将我的应用程序逻辑放在下面:

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标头,以便验证它们。有人可以帮忙。

1 个答案:

答案 0 :(得分:6)

对于远程方法accepts,请使用 -

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

请求标头必须在req.headers

中可用

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