guzba / mummy

An HTTP and WebSocket server for Nim that returns to the ancient ways of threads.
MIT License
281 stars 11 forks source link

[Question/FR?] middleware/route groups? #77

Closed ITwrx closed 1 year ago

ITwrx commented 1 year ago

I tried to implement middleware with route groups, but mummy's RequestHandler only expects Request to be passed, so i was unable to pass a secondary handler id. My simple/naive idea was to pass all routes for a protected group (/admin, for example) through a middleware proc that would check for auth, and if succeeded, pass request to correct RequestHandler proc.

Are middlewares and route groups already supported some way, and i'm just not seeing how to do it, or is this something that could use/would require some new code for mummy? For now, i just decided to check auth on every protected route's RequestHandler proc, but this is a little bothersome to my OCD. :)

ITwrx commented 1 year ago

It looks like this thorough and well-commented example may answer all my questions on middleware/custom handlers, and custom responses. Closing for now. thanks a lot, @guzba !