gpt4 book ai didi

java - 具有非默认应用引擎服务的 Google Cloud Endpoints v2 自定义域

转载 作者:太空宇宙 更新时间:2023-11-04 10:52:04 24 4
gpt4 key购买 nike

我已成功将 Google Cloud Endpoints v2 API 和 App Engine 后端部署到 endpoint-dot-example.appspot.com,并且可以在端点控制台中查看指标。

构建.gradle:

endpointsServer {
hostname = "endpoint-dot-example.appspot.com"
}

appengine-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。为此,我在我的注册处将 URL 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>

最佳答案

解决这个问题的方法是为 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])

调度.yaml:

# Send requests to api.example.com to the "api" service
- url: "api.example.com/*"
service: api

关于java - 具有非默认应用引擎服务的 Google Cloud Endpoints v2 自定义域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47709744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com