Starlette catch all routes and http methods

Question:

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?

Asked By: Rodrigo

||

Answers:

Try using an optional, catch-all path.

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

It can be empty OR anything else.

Answered By: Tom Wojcik
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.