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

部署Cosmos DB后执行swa start遇DataApiBuilderException错误求助

问题:Azure Static Web Apps集成Cosmos DB时DataApiBuilder启动失败

按照Azure Static Web Apps集成Cosmos DB官方教程操作,执行命令:

swa start src --api-location api --data-api-location swa-db-connections

触发DataApiBuilderException错误,错误信息为:

OpenAPI description document can't be created when the REST endpoint is disabled globally

移除--data-api-location swa-db-connections参数后命令可正常运行,已尝试重新创建数据库及相关配置文件,但问题仍未解决。


运行日志输出

Welcome to Azure Static Web Apps CLI (1.1.4)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

[dataApi] Information: Microsoft.DataApiBuilder 0.9.6-rc+529471ba3b50e617439c57548891fdff7ec1c3fa
[dataApi] Information: User provided config file: staticwebapp.database.config.json
[dataApi] Loading config file from staticwebapp.database.config.json.
[dataApi] Information: Loaded config file: staticwebapp.database.config.json
[dataApi] Information: Setting default minimum LogLevel: Error for Production mode.
[dataApi] Starting the runtime engine...
[dataApi] Redirecting to https is disabled.
[dataApi] Loading config file from staticwebapp.database.config.json.
[swa]
[swa] Using workflow file:
[swa]   C:\Users\alexa\source\repos\az-lead\.github\workflows\azure-static-web-apps-icy-pebble-0c3175610.yml
[dataApi] info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
[dataApi]       User profile is available. Using 'C:\Users\alexa\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[dataApi] fail: Azure.DataApiBuilder.Service.Startup[0]
[dataApi]       OpenAPI Documentor initialization failed.
[dataApi]       Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: OpenAPI description document can't be created when the REST endpoint is disabled globally.
[dataApi]          at Azure.DataApiBuilder.Core.Services.OpenApiDocumentor.CreateDocument() in /_/src/Core/Services/OpenAPI/OpenApiDocumentor.cs:line 108
[dataApi]          at Azure.DataApiBuilder.Service.Startup.PerformOnConfigChangeAsync(IApplicationBuilder app) in /_/src/Service/Startup.cs:line 687
[dataApi] Unable to launch the runtime due to an error.
[dataApi] Error: Failed to start the engine.
[dataApi] cd "C:\Users\alexa\source\repos\az-lead\swa-db-connections" && "C:\Users\alexa\.swa\dataApiBuilder\0.9.6-rc\Microsoft.DataApiBuilder.exe" start -c staticwebapp.database.config.json --no-https-redirect exited with code 0
--> Sending SIGTERM to other processes..
[swa] node "C:\Users\alexa\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 1
✖ SWA emulator stoped because SWA emulator exited with code 1.

staticwebapp.database.config.json 配置文件

{
  "$schema": "https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json",
  "data-source": {
    "database-type": "cosmosdb_nosql",
    "options": {
      "database": "MyTestPersonDatabase",
      "schema": "staticwebapp.database.schema.gql"
    },
    "connection-string": "@env('DATABASE_CONNECTION_STRING')"
  },
  "runtime": {
    "graphql": {
      "allow-introspection": true,
      "enabled": true,
      "path": "/graphql"
    },
    "host": {
      "mode": "production",
      "cors": {
        "origins": ["http://localhost:4280"],
        "allow-credentials": false
      },
      "authentication": {
        "provider": "StaticWebApps"
      }
    }
  },
  "entities": {
    "Person": {
      "source": "MyTestPersonContainer",
      "permissions": [
        {
          "actions": ["*"],
          "role": "anonymous"
        }
      ]
    }
  }
}

staticwebapp.database.schema.gql 配置文件

type Person @model {
  id: ID
  Name: String
}

staticwebapp.config.json 配置文件

{
    "responseOverrides": {
      "404": {
        "rewrite": "/404.html"
      },
      "401": {
        "redirect": "/.auth/login/aad?post_login_redirect_uri=.referrer",
        "statusCode": 302
      }
    },
    "routes": [
      {
        "route": "/admin*",
        "allowedRoles": ["administrator"]
      },
      {
        "route": "/company*",
        "allowedRoles": ["operator", "manager"]
      },
      {
        "route": "/api/postLogin",
        "allowedRoles": ["authenticated"]
      },
      {
        "route": "/.auth/login/twitter",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/github",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/google",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/facebook",
        "statusCode": 404
      }
    ]
  }

内容的提问来源于stack exchange,提问作者Alexandre Heuschkel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 01:42:43