【问题标题】:Starlette catch all routes and http methodsStarlette catch all routes and http methods
【发布时间】:2022-12-27 01:17:11
【问题描述】:

I want to make my function proxy accepts ALL paths and all HTTP methods, everything that hits the Starlette app I want to proxy function handles it.

async def proxy(request: Request):
    pass


routes = [
    Route("/", endpoint=proxy),
]

app = Starlette(routes=routes)

I tried the code above, but no luck.

How to do this?

【问题讨论】:

    标签: python starlette


    【解决方案1】:

    Try using an optional, catch-all path.

    routes = [
        Route("/{path:path}", endpoint=proxy),
    ]
    

    It can be empty OR anything else.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-02
      • 2011-12-28
      • 2021-12-27
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多