1
votes

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.

build.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>

I now wish to serve this API from a custom domain. For that I have routed a URL api.example.com to example.appspot.com at my registra and changed the hostname in build.gradle:

endpointsServer {
    hostname = "api.example.com"
}

But I am getting 404 error when making requests with the custom domain. 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?

Edit 1 This is the 404 response body:

<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>

1
Can you show what the 404 error format looks like?saiyr
@saiyr I have edited my question with the response bodyHeigo
@Heigo Did you make any progress on this? I'm in the exact same situation.Jeremy
@Jeremy No progressHeigo

1 Answers

0
votes

The way around this is to use a custom base path for your Endpoints API.

It appears /_ah/ URLs can bypass dispatch rules from dispatch.yaml, especially with non-default services. But with a custom base path that isn't /_ah/, they work fine.

Here is an example, in Python, of a non-default service running an API at api.example.com/api/v1/*.

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