You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Function创建含/config.yaml端点:解决非法字符'.'问题

在Azure Function中创建含'.'的端点(如/config.yaml)

首先你对Python代码里的端点理解完全正确,就是要对外暴露/config.yaml这个路径。Azure Function默认会把路径中的.识别为文件扩展名,导致路由匹配失败,你可以通过以下方式解决:

1. 调整function.json的路由配置

在函数的function.json文件中,修改HTTP触发器的绑定规则,明确指定路由并按需调整前缀:

{
  "scriptFile": "__init__.py", // 根据使用语言替换,比如C#填"../bin/YourFunction.dll"
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": ["get"],
      "route": "config.yaml",
      "routePrefix": ""
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}
  • routePrefix设为空是为了去掉Azure Function默认的api前缀,让路径直接是/config.yaml;如果需要保留api前缀,只需把route设为api/config.yaml,无需修改routePrefix。

2. 语言特定的路由配置(以C#为例)

如果使用C#开发Azure Function,除了配置function.json,还可以在函数方法上通过[Route]特性直接指定路径:

public static class ConfigYamlFunction
{
    [FunctionName("ConfigYaml")]
    [Route("config.yaml")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
        ILogger log)
    {
        // 编写你的业务逻辑,返回对应内容
        return new OkObjectResult("你的config.yaml内容");
    }
}

确保[Route]特性的路径和function.json中的配置一致即可。

3. 验证端点

部署完成后,直接访问https://<你的函数应用名>.azurewebsites.net/config.yaml(保留api前缀则访问https://<你的函数应用名>.azurewebsites.net/api/config.yaml),确认能正常返回预期内容。

内容的提问来源于stack exchange,提问作者Doug Finke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 15:32:40