solara
solara copied to clipboard
Solara middleware support example request
Hello,
Would it be possible to get (at least) a very minimal example of adding some custom middleware on a basic solara server (just the default starlette thing we get via solara run my_app.py.
I would really like (need) to add some custom logging, measure timing, rate limits etc..
It would be extra nice if I could log per route or so.
A very minimal example would be highly appreciated, if possible.
Thank you! Jovan.
Hi Jovan,
Do you want to log specific actions of users? Beause a starlette middleware will not help (since we only have the initial websocket request). If you want to log specific page visits (e.g. using mixpanel), you could use the top layout, would you like an example for that?
cheers,
Maarten
Hi,
I had 2 goals with this question:
- Just to learn how to add middleware for whatever purpose (and if that was possible/supported in solara)
- Actually just to log the initial websocket request (i realized this once I figured how to do this - but good enough for me).
So I realized you can get access to the underlying starlette app via from solara.server.starlette import app as starlette_app and then starlette_app.add_middleware(...). In the starlette docs there is already some info on how to write middleware.
So i think it is ok to close this! Thank you!