我正在尝试使用 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
,采用 QuickStart 指定的格式
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 控制台,我可以看到应用程序正常运行。
然而, GET 方法/
并没有被识别为有效端点,我得到了如上所述的响应。
我错过了什么吗?我对这个问题进行了很多搜索,但没有发现任何有用/类似的东西!
PS:添加的意思是我添加到相应的GitHub克隆文件中的代码
编辑:
我将 API 端点从更改/
为/hello
,它工作正常!!无法理解为什么相同的功能在/
Google Cloud Endpoints 上不起作用(虽然在本地工作!)