【问题标题】:How do I pass "x-ms-client-principal" in Azure Static Website Hosting (Preview) when running locally?在本地运行时,如何在 Azure 静态网站托管(预览版)中传递“x-ms-client-principal”?
【发布时间】:2020-06-03 00:02:46
【问题描述】:

我正在试用新的 Azure 静态网站托管预览版,在本地运行时,Azure 函数在 req 绑定对象中没有收到“x-ms-client-principle”标头。

我的路线文件如下所示:

{
  "routes": [
    {
      "route": "/api/*",
      "allowedRoles": ["administrator"]
    },
    {
      "route": "/*",
      "serve": "/index.html",
      "statusCode": 200
    }
  ]
}

我的 API 函数被命中:/api/message,但不包括标题。

module.exports = async function (context, req) {
  const header = req.headers["x-ms-client-principal"]; // req.headers doesn't include x-ms-client-principle
  const encoded = Buffer.from(header, "base64");
  const decoded = encoded.toString("ascii");
}

静态应用是使用 create-react-app 创建的 React 静态页面。我有一行打印出 react-app 的结果:

fetch(`${process.env.REACT_APP_API}/message?name=me`)
  .then(a => a.text())
  .then(console.log);

本地process.env.REACT_APP_API 是通过REACT_APP_API=http://127.0.0.1:7071/api 设置的。

API 受到攻击,但我不确定它是否运行正确版本的 Azure Functions。它正在报告:Function Runtime Version: 2.0.12961.0,即使我已经安装了 azure-functions-core-tools@3,并在 settings.json 中设置了正确的值 ("azureFunctions.projectRuntime": "~3")。

我的问题是我错过了什么,如果有,是什么?

【问题讨论】:

标签: reactjs azure azure-functions azure-static-website-hosting


【解决方案1】:

目前看来,这不是一个受支持的方案:

https://github.com/MicrosoftDocs/azure-docs/issues/55517

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 1970-01-01
    • 2017-08-13
    • 2021-12-07
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多