我正在尝试使用 Google Cloud Endpoints 和 Google App Engine 设置 NodeJS REST API。我已经从 GitHub 克隆了官方示例项目并使用 Quickstart 设置 Google Cloud Endpoints 。开箱即用,它工作正常,但我尝试在 /
处为 GET 请求添加另一个 API 端点,但部署并发出请求后得到的响应如下:
{
"code": 5,
"message": "Method does not exist.",
"details": [
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"stackEntries": [],
"detail": "service_control"
}
]
}
预先配置的 API 工作正常,但只有我添加的新 API 无法工作。
我已经在 NodeJS 应用程序中正确配置了新端点(它在本地运行良好)。我添加的相应代码是:
app.get('/', function (req, res) {
res.status(200).json({ message: 'Hello, world!' });
});
我已将以下内容添加到我的 openapi.yaml
文件中:
paths:
"/":
get:
description: "Returns the message \"Hello, World\""
operationId: "root"
produces:
- "application/json"
responses:
200:
description: "Hello"
schema:
$ref: "#/definitions/helloMessage"
definitions:
helloMessage:
properties:
message:
type: "string"
从终端运行 gcloud service-management deploy openapi.yaml
来部署和配置 Google Cloud Endpoints 后,我获得了服务名称和服务配置 ID,我已将其替换为 app.yaml
,采用快速入门指定的格式
endpoints_api_service:
name: echo-api.endpoints.[YOUR-PROJECT-ID].cloud.goog
config_id: YOUR-CONFIG-ID
(这就是格式,我已将 YOUR-PROJECT-ID
和 YOUR-CONFIG-ID
替换为正确的格式)
我使用 gcloud app deploy
将应用部署到 Google App Engine。我可以通过 Google App Engine 控制台看到该应用正常运行。
但是,/
上的 GET 方法未被识别为有效端点,我得到了如上所述的响应。
我错过了什么吗?我搜索了很多关于这个问题的信息,但没有发现任何有用/类似的东西!
P.S:通过添加,我的意思是,这是我添加到相应GitHub cloned files中的代码。
编辑:
我将 API 端点从 /
更改为 /hello
并且工作正常!无法理解为什么 /
上的相同功能无法在 Google Cloud Endpoints 上运行(但可以在本地运行!)
最佳答案
Google Cloud Endpoints 目前不支持“/”处的根路径。这是正在研究的事情。
关于node.js - Google Cloud Endpoints - 方法不存在 - OpenAPI yaml 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43097453/