Middleware
has the type Application -> Application
. So if you
want to turn someApplication
into Middleware
, a way you could do
it is:
staticMiddleware :: Middleware
staticMiddleware = \app -> someApplication
You throw away an argument that is an Application
and return the
application you want, and now you have Middleware
!
Probably not very useful Middleware
. You may want to look at the
request to figure out how to handle it? Like, some requests are going
to be handled by this static server middleware, and others are going
to be handled your regular server?
Maybe you could do something like this:
someMiddleware :: Middleware
someMiddleware = \app -> branchingApp
branchingApp :: Application
branchingApp req functionReqToRecieved =
if iWantToStaticServeThis req
then staticApp req functionReqToRecieved
else dynamicApp req functionReqToRecieved
This is terrible code so please don't copy but I hope it gets the idea across?
An Application
is a function: Request -> (Response -> IO
ResponseReceived) -> IO ResponseReceived
. I want to say how to use
that first argument (the request). So, instead of saying this
Middleware
returns this predefined application, I'm constructing my
own Application
, that just takes a look at the Request
and decides
which Application
should handle it. Then it passes the arguments
back to the Application
.
There might be a helper function somewhere that does this for you,
too, but I'm not sure.