我已成功将Google Cloud Endpoints v2 API和App Engine后端部署到endpoint-dot-example.appspot.com
,我可以在端点控制台中查看指标。
的build.gradle:
endpointsServer {
hostname = "endpoint-dot-example.appspot.com"
}
应用服务引擎-web.xml中:
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="endpoint-dot-example.appspot.com"/>
</env-variables>
的web.xml:
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>example</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>endpoint-dot-example.appspot.com</param-value>
</init-param>
</filter>
我现在希望从自定义域提供此API。
为此,我在注册表中将api.example.com
路由到example.appspot.com
并更改了build.gradle中的主机名:
endpointsServer {
hostname = "api.example.com"
}
但是在使用自定义域发出请求时出现404错误。我还可以在stackdriver日志中看到默认服务的日志。 如何告诉应用引擎将请求路由到API?
修改1 这是404响应机构:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 NOT_FOUND</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: NOT_FOUND</h1>
</body>
答案 0 :(得分:0)
解决方法是为Endpoints API使用自定义基本路径。
似乎/_ah/
的URL可以绕过dispatch.yaml
的调度规则,尤其是对于非默认服务。但是,使用不是/_ah/
的自定义基本路径,它们可以正常工作。
在Python中,这是一个非默认服务的示例,该服务在api.example.com/api/v1/*
上运行API。
app.yaml:
- url: .*
script: api.app
api.py:
api_collection = endpoints.api(
name='api',
version='v1',
base_path='/',
description='Example API',
api_key_required=False,
scopes=[],
audiences=[])
app = endpoints.api_server([api_collection])
dispatch.yaml:
# Send requests to api.example.com to the "api" service
- url: "api.example.com/*"
service: api