[英]Google Cloud Endpoints v2 custom domain with non-default app engine service
I have successfully deployed a Google Cloud Endpoints v2 API and a App Engine backend to endpoint-dot-example.appspot.com
and I can see the metrics in the endpoints console. 我已将Google Cloud Endpoints v2 API和App Engine后端成功部署到
endpoint-dot-example.appspot.com
并且可以在终结点控制台中查看指标。
build.gradle: build.gradle:
endpointsServer {
hostname = "endpoint-dot-example.appspot.com"
}
appengine-web.xml: appengine-web.xml:
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="endpoint-dot-example.appspot.com"/>
</env-variables>
web.xml: 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>
I now wish to serve this API from a custom domain. 我现在希望从自定义域提供此API。 For that I have routed a URL
api.example.com
to example.appspot.com
at my registra and changed the hostname in build.gradle: 为此,我在我的注册处将URL
api.example.com
路由到example.appspot.com
,并在build.gradle中更改了主机名:
endpointsServer {
hostname = "api.example.com"
}
But I am getting 404 error when making requests with the custom domain. 但是使用自定义域发出请求时出现404错误。 I can also see the logs in the stackdriver logging for the default service.
我还可以在堆栈驱动程序日志中看到默认服务的日志。 How can I tell app engine to route the requests to the API?
如何告诉应用引擎将请求路由到API?
Edit 1 This is the 404 response body: 编辑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>
The way around this is to use a custom base path for your Endpoints API. 解决方法是为Endpoints API使用自定义基本路径。
It appears /_ah/
URLs can bypass dispatch rules from dispatch.yaml
, especially with non-default services. 看来
/_ah/
URL可以从旁路调度规则dispatch.yaml
,尤其是与非默认服务。 But with a custom base path that isn't /_ah/
, they work fine. 但是,使用不是
/_ah/
的自定义基本路径,它们可以正常工作。
Here is an example, in Python, of a non-default service running an API at api.example.com/api/v1/*
. 这是一个使用Python的非默认服务示例,该服务在
api.example.com/api/v1/*
运行API。
app.yaml: app.yaml:
- url: .*
script: api.app
api.py: 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: dispatch.yaml:
# Send requests to api.example.com to the "api" service
- url: "api.example.com/*"
service: api
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.