i am using servant
and Network.Wai.Application.Static
for json api and static file serving respectively. I want to join these two Application such that if staticApp
fails to serve, request should go to jsonApp
.
I tried finding out and read how websocketsOr
has done it.WebsocketsOr
I finally wrote :
app :: NW.Application -> NW.Application -> NW.Application
app staticApp apiApp req respond =
staticApp req (\ response ->
do
if (Status.statusCode . NW.responseStatus $ response) < 300
then respond response
else apiApp req respond)
But it seems like someone else (wai itself) would have done it, handling many possible cases.. But i am not able to find.
What are the edges cases i am missing (exceptions ?? ) and what other api can i use to do the same ?