blob: 4798ec1f90a74b84984516358b0b9e5fc1b9e33f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
module Router where
import Control.Exception
import Response
import Request
data Route = Route (Request -> IO Response) String String
data RouterError = RouteNotFound
deriving Show
instance Exception RouterError
getResponse [] _ = throw RouteNotFound
getResponse (Route callback routeUrl _ : routerTable) req @ (Request _ url _) =
if url == routeUrl then
callback req
else getResponse routerTable req
router table req =
|