【问题标题】:Is it possible to host endpoint and WSGIApplication application in the same app engine project是否可以在同一个应用引擎项目中托管端点和 WSGIApplication 应用程序
【发布时间】:2016-10-19 08:12:20
【问题描述】:

我实现了端点项目:

@endpoints.api(name='froom', version='v1', description='froom API')
class FRoomApi(remote.Service):   
    @endpoints.method(FbPutRoomRequest, RoomMessage, path='putroom/{id}', http_method='PUT', name='putroom')
    def put_room(self, request):
        entity = FRoom().put_room(request, request.id)
        return entity.to_request_message()

application = endpoints.api_server([FRoomApi],restricted=False)

app.yaml

- url: /_ah/spi/.*
  script: froomMain.application 

- url: .*
  static_files: index.html
  upload: index.html

我有单独的 wsgi-jinja 项目:

routes = [
    Route(r'/', handler='handlers.PageHandler:root', name='pages-root'),
    # Wipe DS
    Route(r'/tasks/wipe-ds', handler='handlers.WipeDSHandler', name='wipe-ds'),
    ]
config = {
    'webapp2_extras.sessions': {
        'secret_key': 'someKey'
    },
    'webapp2_extras.jinja2': {
        'filters': {
            'do_pprint': do_pprint,
            },
        },
    }
application = webapp2.WSGIApplication(routes, debug=DEBUG, config=config)

app.yaml

- url: /.*
  script: froomMain.application

是否可以在同一个应用程序中托管这两个项目

【问题讨论】:

    标签: python google-app-engine wsgi endpoint


    【解决方案1】:

    需要解决的基本问题是定义适当的整体应用请求命名空间,以便可靠地路由到适当的子应用,请记住:

    • 只能将一个子应用指定为默认子应用(它将处理与任何其他子应用命名空间不匹配的请求)。
    • 所有非默认子应用的命名空间必须在默认子应用的命名空间之前检查
    • 路由到一个子应用的决定是最终决定,如果它无法处理请求,它将返回 404,不会回退到可能能够处理请求的另一个子应用

    在您的情况下,复杂性来自子应用程序的命名空间冲突。例如,来自 wsgi-jinja 项目的 //tasks/wipe-ds 路径都与端点项目中的 .* 命名空间发生冲突。要使其工作,必须修改子应用名称空间之一。

    由于端点项目包含大量自动生成的代码,因此更难更改,因此我将其保留为默认代码并修改 wsgi-jinja 代码,例如在其前面加上 /www 前缀.为此,需要相应地修改 wsgi-jinja 的内部路由:

    • / -> /www
    • /tasks/wipe-ds -> /www/tasks/wipe-ds

    您现有的两个项目似乎都有一个 froomMain.py 文件,其中包含一个 application 全局文件,相互冲突。我会重命名 wsgi-jinja 的名字,比如说www.py

    routes = [
        Route(r'/www/', handler='handlers.PageHandler:root', name='pages-root'),
        # Wipe DS
        Route(r'/www/tasks/wipe-ds', handler='handlers.WipeDSHandler', name='wipe-ds'),
        ]
    config = {
        'webapp2_extras.sessions': {
            'secret_key': 'someKey'
        },
        'webapp2_extras.jinja2': {
            'filters': {
                'do_pprint': do_pprint,
                },
            },
        }
    application = webapp2.WSGIApplication(routes, debug=DEBUG, config=config)
    

    您的app.yaml 文件将是:

    - url: /www/.*
      script: www.application
    
    - url: /_ah/spi/.*
      script: froomMain.application 
    
    - url: .*
      static_files: index.html
      upload: index.html
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2011-06-19
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 2013-02-07
      相关资源
      最近更新 更多