发出 OPTIONS 请求时执行的 Azure 函数应用程序?

Azure function app executing when OPTIONS request made?

我使用 Azure 门户创建了一个函数应用程序。我检查了 POST 和 OPTIONS 作为允许的方法。我删除了默认的 CORS 设置并允许 *.现在,当我使用 REST 客户端发出 OPTIONS 请求时,我收到返回的错误。我检查了日志并发现了以下内容。我的问题:听起来我的函数可能正在执行,当没有授权 header and/or 没有找到有效载荷时,它会抛出错误。也许我不明白 OPTIONS 请求。在 Azure 门户功能应用中防止这种情况发生的选项有哪些?

TIA 寻求任何帮助。

2019-05-17T09:16:26.479 [Info] Executing HTTP request: {
  "requestId": "38609669-59f4-4ded-9685-ef67af3c2909",
  "method": "OPTIONS",
  "uri": "/api/ProcessEntries"
}
2019-05-17T09:16:26.479 [Info,ProcessEntries] Function started (Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.479 [Info,ProcessEntries] Executing 'Functions.ProcessEntries' (Reason='This function was programmatically called via the host APIs.', Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.495 [Error] A ScriptHost error has occurred
2019-05-17T09:16:26.495 [Error] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.526 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Anonymously Hosted DynamicMethods Assembly: Cannot perform runtime binding on a null reference.
2019-05-17T09:16:26.573 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function completed (Failure, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6, Duration=87ms)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Executed 'Functions.ProcessEntries' (Failed, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '41b4691d-98ec-432f-8e6e-de1e1dcd13b6'
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.588 [Error] {"id":"eada812b-1530-4d26-85e3-4c6e6e243f01","requestId":"38609669-59f4-4ded-9685-ef67af3c2909","statusCode":500,"errorCode":0,"message":"An error has occurred. For more information, please check the logs for error ID eada812b-1530-4d26-85e3-4c6e6e243f01"}
2019-05-17T09:16:26.588 [Error] Cannot perform runtime binding on a null reference


也许回答我自己的问题(这不是真正的答案)让我 post 以更清晰的方式 follow-up。

我不明白为什么选项请求会寻找要绑定的东西。我能理解为什么我的功能会,是的。它确实与某些存储帐户相关联,并且确实需要有效负载。但是为什么选项请求会关心其中的任何一个呢?是否正在尝试执行该功能?


{
  "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "post",
        "options"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "table",
      "name": "outShazamPayloadsTable",
      "tableName": "czShazamPayloadsTable",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "czshazamqueue",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    }
  ],
  "disabled": false
}

万一以后有人遇到这个...

原来问题是即使发送了 OPTIONS 请求,我的函数应用程序仍在执行。我没想到的是。它正在轰炸,因为它没有发送任何有效载荷。由于项目的性质,我知道总会有一个带有 POST 的有效载荷,并且从未考虑过 OPTIONS 请求也会执行该代码。一旦我在我的函数中进行了一些空检查,一切都很好,我开始接收 status = 200 的 OPTIONS 请求。

我想我应该记住,从来没有什么事情是确定的。