swagger AWS Lambda将$default添加到flagger apispec的路径

mgdq6dx1  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(177)

AWS Lambda请求URL为:我的网站是一个很好的网站,我的网站是一个很好的网站。
Screenshot
URL应该是https://.. amazonaws.com/apispec.json
当我手动删除$default时,这是很好的。
这是困扰我们,所以如果有人能帮助我们,这将是非常感谢。
Swagger配置:

swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js'
swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js'
swagger_config['jquery_js'] = '//unpkg.com/jquery@2.2.4/dist/jquery.min.js'
swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css'

# swagger_config['specs'][0] = {'endpoint':'/cms-api/apispec','route':'/cms-api/apispec.json'}

Swagger(app, config=swagger_config, template=template)

摆动配置

swagger_config = {
    "headers": [

    ],
    "specs": [
        {
            "endpoint": 'apispec',
            "route": '/apispec.json',
            "rule_filter": lambda rule: True,  # all in
            "model_filter": lambda tag: True,  # all in
        }
    ],
    "static_url_path": "/flasgger_static",
    "swagger_ui": True,
    "specs_route": "/cms-api"
}

serverless.yml

service: cms-backend

frameworkVersion: '3'

custom:
  wsgi:
    app: src.__init__.app

provider:
  name: aws
  stage: ${opt:stage, 'dev'}
  runtime: python3.8
  logs:
    httpApi: true
  httpApi:
    metrics: true
    cors: true
  region: ap-southeast-1

functions:
  app:
    handler: wsgi_handler.handler
    events:
      - httpApi: '*'

plugins:
  - serverless-wsgi
  - serverless-python-requirements
1dkrff03

1dkrff031#

遇到了一个类似的问题,我花了很长时间才弄清楚,但结果发现它与API gateway stages有关。Serverless没有使用这个功能,只是为不同的阶段部署了一个新功能。
如果你没有使用API网关的stage,试着通过添加STRIP_STAGE_PATH环境变量来忽略它们,就像serverless-wsgi documentation中提到的那样。它应该会从你的路径中忽略$default stage变量:

provider:
  environment:
    STRIP_STAGE_PATH: yes

(This是source code of the serverless_wsgi module的代码片段):

def get_script_name(headers, request_context):
    strip_stage_path = os.environ.get("STRIP_STAGE_PATH", "").lower().strip() in
        [
        "yes",
        "y",
        "true",
        "t",
        "1",
    ]

    if "amazonaws.com" in headers.get("Host", "") and not strip_stage_path:
        script_name = "/{}".format(request_context.get("stage", ""))
    else:
        script_name = ""
    return script_name

相关问题