rgrinberg / opium

Sinatra like web toolkit for OCaml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selectively applied authorization middleware

chrismamo1 opened this issue · comments

I would like for some of my handlers to be behind an authorization middleware, and other to be accessible to the general public (e.g account creation, splash page, etc). From what I gather, there is no idiomatic way to accomplish with with Opium. I don't mind brewing my own solution, I'll have to do the work sooner or later anyway. But am I missing something?

@chrismamo1 At the moment, I am doing this by wrapping individual handlers with Rock.Middleware.apply. I defined it as @@@, so my handlers that need special middleware look like:

let handler =
    some_middleware @@@
    some_more_middleware @@@
    fun req ->
  (* ... *)

You could also look at Sihl, which allows applying a group of middlewares to a group of routes.

In short, it seems you'll need your own solution to some degree.