我正在尝试按照本教程中的说明进行操作,但在尝试运行时遇到错误
swa start
swa start src --api-location api --data-api-location swa-db-connections
在尝试实现 Cosmos DB 之前,一切都工作正常,因此,如果我运行不带
--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
}
]
}
我已经尝试过:
感谢您尝试数据 API 构建器,对于迄今为止给您带来的不便,我深表歉意。从日志和提供的配置来看,似乎没有任何明显的原因不启动服务器。日志中的 OpenApiDocument 创建失败应该不是问题,因为没有为 cosmosdb 启用其余 api。为了进一步调查,您能否将配置中的 host.mode 属性从“生产”修改为“开发”并再次运行。这将为我们提供更多日志以了解可能发生的情况。
干杯, 阿尼鲁