Skip to content

Commit

Permalink
Inline getRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-k committed Oct 21, 2023
1 parent 8583796 commit 487fde5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mig/src/Mig/Core/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ mapResponse f = mapServerFun $ \fun -> fmap (fmap f) . fun
{-| Converts server to server function. Server function can be used to implement low-level handlers
in various server-libraries.
-}
fromServer :: forall m. (Monad m) => Server m -> ServerFun m
fromServer :: (Monad m) => Server m -> ServerFun m
fromServer (Server server) = \req -> do
case getRoute req of
Just (routes, captureMap) -> routes.run req{capture = captureMap}
Nothing -> pure Nothing
where
serverNormal = toNormalApi (fillCaptures server)

getRoute :: Request -> Maybe (Route m, Api.CaptureMap)
getRoute req = do
api <- fromNormalApi key.method key.outputType key.inputType serverNormal
Api.getPath key.path api
where
key = getCacheKey req
api <- fromNormalApi req.method (getMediaType "Accept" req) (getMediaType "Content-Type" req) serverNormal
Api.getPath req.path api

getMediaType name req = fromMaybe "*/*" $ Map.lookup name req.headers

{-| Converts server to server function. Server function can be used to implement low-level handlers
in various server-libraries. This function also uses LRU-cache to cache fetching of
Expand Down

0 comments on commit 487fde5

Please sign in to comment.