You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can we add a function Dream.use : middleware list -> route list -> route to add middlewares to a bunch of routes without needing a scope prefix? My use case is that in bidirectional routing, we typically create route or path 'objects' which need to be able to print out the correct path for linking purposes:
let order = [%path "/orders/%s"]
let get_order = get order (funrequestorder_id ->
...
a [href (Path.link order) order_id] [txt "Your order"]
...
)
If we attach a middleware to this route with eg Dream.scope "/v2" [v2] [get_order], the path object no longer captures the correct routable path, which will be /v2/orders/:param3. But if we capture the full path:
let order = [%path "/v2/orders/%s"]
Then we need to attach middlewares without a prefix:
use [v2] [
get_order;
post_order;
delete_order;
]
I have a simple working implementation now:
letusemiddlewares=Dream.scope "" middlewares
But something tells me this may not be the best approach. Could we support it directly in Dream?
Can we add a function
Dream.use : middleware list -> route list -> route
to add middlewares to a bunch of routes without needing a scope prefix? My use case is that in bidirectional routing, we typically create route or path 'objects' which need to be able to print out the correct path for linking purposes:If we attach a middleware to this route with eg
Dream.scope "/v2" [v2] [get_order]
, the path object no longer captures the correct routable path, which will be/v2/orders/:param3
. But if we capture the full path:Then we need to attach middlewares without a prefix:
I have a simple working implementation now:
But something tells me this may not be the best approach. Could we support it directly in Dream?
EDIT: prior art for the name
use
:EDIT 2: the OCaml website people are also doing
Dream.scope ""
: https://github.com/ocaml/ocaml.org/blob/5ac9eea5813c8813d4a562958af7a99d910bba81/src/ocamlorg_web/lib/router.ml#L79The text was updated successfully, but these errors were encountered: