【发布时间】:2017-08-23 04:10:18
【问题描述】:
我正在尝试使用 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 上运行(但在本地运行!)
【问题讨论】:
标签: node.js google-app-engine swagger google-cloud-endpoints openapi