【问题标题】:Using Google endpoints in different modules of the same app在同一应用的不同模块中使用 Google 端点
【发布时间】:2016-09-07 02:02:42
【问题描述】:

我对使用 Google App 引擎和云平台的其他 Google 服务进行开发非常陌生,我想创建一个具有不同模块(因此它们可以有自己的生命周期)并使用端点的应用程序。

我在 api 路径上苦苦挣扎,因为我不知道如何将请求路由到好的模块。

我的目录树是这样的:

/myApp
  /module1
    __init__.py
    main.py
  /module2
    __init__.py
    main.py
  module1.yaml
  module2.yaml
  dispatch.yaml

module1.yaml

application: myapp
runtime: python27
threadsafe: true
module: module1
version: 0
api_version: 1

handlers:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
  script: module1.main.api

libraries:
- name: pycrypto
  version: 2.6
- name: endpoints
  version: 1.0

module2.yaml

application: myapp
runtime: python27
threadsafe: true
module: module2
version: 0
api_version: 1

handlers:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
  script: module2.main.api

libraries:
- name: pycrypto
  version: 2.6
- name: endpoints
  version: 1.0

dispatch.yaml

dispatch:
  - url: "*/_ah/spi/*"
    module: module1

  - url: "*/_ah/spi/.*"
    module: module2

所以我希望在某处使用相应模块的名称('_ah/api/module1' 或'module1/_ah/api')来调用我的端点。我不知道在不同的 .yaml 文件中放什么。我什至不知道我在做什么是对的,还是可能的。

感谢您的回答。

【问题讨论】:

    标签: python-2.7 google-app-engine google-cloud-endpoints


    【解决方案1】:

    您可以在不同的模块上托管不同的端点(现在称为服务);正确处理它们的方法如下:

    https://<service-name>-dot-<your-project-id>.appspot.com/_ah/api

    现在,假设您拥有(根据您的描述)module1module2,每个都托管不同的端点。您将通过点击调用 module1 API:

    https://module1-dot-<your-project-id>.appspot.com/_ah/api

    以类似的方式,module2 API:

    https://module2-dot-<your-project-id>.appspot.com/_ah/api

    如果您想深入了解此 URL 架构的工作原理(包括版本,这是此处等式的另一个重要部分),请阅读 Addressing microservices 和紧随其后的部分 Using API versions

    【讨论】:

    • 感谢您的帮助。我现在遇到了一个新问题,这里描述为stackoverflow.com/questions/37183193/…,所以我将这个问题设置为已解决
    • 其实我还是想看看 .yaml 文件的样子。特别是该应用程序可以在开发服务器和云中运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 2019-06-03
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多