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
With some digging I found that the method information from Piaf is actually hidden under request.request.meth so maybe we want to somehow map this to request.method directly (changing Morph.Request.t).
I came up with the following which appears to work.
let method_to_string : Piaf.Method.t => string = fun
| `GET => "GET"
| `POST => "POST"
| `PUT => "PUT"
| `DELETE => "DELETE"
| `HEAD => "HEAD"
| `OPTIONS => "OPTIONS"
| `TRACE => "TRACE"
| `CONNECT => "CONNECT"
| `Other(s) => {j|UNKNOWN($s)|j}
;
/**
* Creates a new logger middleware.
*
* The output of this function can be passed to the middlewares
* argument of `Morph.start`.
*/
let make = () => {
(service) => (request: Morph.Request.t) => {
open Lwt.Infix;
let start_request = Mtime_clock.elapsed();
service(request)
>|= (
response => {
let end_request = Mtime_clock.elapsed();
Logs.info(m =>
m(
"http: %s request to %s finished in %fms",
request.request.meth |> method_to_string,
request.request.target,
Mtime.Span.abs_diff(start_request, end_request)
|> Mtime.Span.to_ms,
)
);
response;
}
);
};
}
The text was updated successfully, but these errors were encountered:
https://reason-native-web.github.io/docs/morph/writing-middlewares makes a reference to
Morph.Method.to_string
but this doesn't actually seem to be in the library.With some digging I found that the method information from Piaf is actually hidden under
request.request.meth
so maybe we want to somehow map this torequest.method
directly (changingMorph.Request.t
).I came up with the following which appears to work.
The text was updated successfully, but these errors were encountered: