问题
Thanks to asamarin I've been able to figure out how to get different endpoints within the same google app engine (cf Using Google endpoints in different modules of the same app).
But I can't make it work (at least with the dev server, I've not tried to pushed it to the cloud). I have two modules: module1 and module2, each of them running an independent api (using google endpoints so). In each moduleX/main.py I have this code:
import endpoints
from protorpc import remote
# ... some code
@endpoints.api(name="moduleX", version='v0') # X being 1 or 2 obviously
class ModuleX(remote.Service):
# ... definition of the different methods
api = endpoints.api_server([ModuleX])
When I run dev_appserver.py with the two corresponding module yaml files, they start well (module1 on localhost:8080, module2 on localhost:8081).
Here comes the problem:
localhost:8080/_ah/api/explore works well and I can see my module1 API with the different methods
localhost:8081/_ah/api/explore takes looooong time then find the exact same API than for module1 except than when I click on it, it can't find the methods.
I've played a bit with Postman to see what's going on under the wood and found out that both calls to localhost:8080/_ah/api/discovery/v1/apis and localhost:8081/_ah... return the same information with the discoveryRestUrl
being localhost:8080/_ah/api/discovery/v1/apis/module1/v0/rest. Which is funny you'll admit.
Am I doing something wrong ? Is it only the dev server that doesn't handle endpoints with multiple services ?
Thanks for your help
回答1:
I believe this issue only exists with dev_appserver, as I had the same problem as you locally but it worked fine once deployed.
My app.yaml for my endpoint service looks like this:
runtime: python27
threadsafe: true
api_version: 1
service: <module-name>
handlers:
- url: /_ah/spi/.*
script: my_script.api
libraries:
- name: pycrypto
version: 2.6
- name: endpoints
version: 1.0
Once deployed, in order to hit my api I send requests to https://<module-name>-dot-<project-name>.appspot.com/_ah/api
So for the code you gave, the endpoint you would need to hit would be https://<module-name>-dot-<project-name>.appspot.com/_ah/api/<moduleX>/v0/<method>
Note that <module-name>
is defined in app.yaml and <moduleX>
and <method>
would be declared in the python code in my_script.api
.
In order to get this working locally on dev_appserver, I believe you need to run each endpoint module in its own instance of dev_appserver, as is noted here. Admittedly I have not gotten this to work fully locally, as when I try to do this I get errors about my datastore being locked, but I believe fixing that issue should be possible as noted here.
来源:https://stackoverflow.com/questions/37183193/unable-to-get-google-endpoints-working-over-multiple-services