view Routes.hs @ 0:622f5598f951

Initial Commit
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Mon, 17 Jun 2013 05:15:33 +0900
parents
children 782efee9766c
line wrap: on
line source

{-# LANGUAGE OverloadedStrings #-}

module Routes (routes) where

import Types
import RouteSetting
import Network.Wai (Response, responseLBS)
import Network.HTTP.Types (status404)
import Network.HTTP.Types.URI (Query)
import Network.Wai.Parse (Param)
import Data.Text (Text)

routes :: [Text] -> (TJungle -> Query -> [Param] -> IO Response)
routes path = findRoute path routeSetting

findRoute path [] = notFound
findRoute path ((p,f):xs)
    | path == p = f
    | otherwise = findRoute path xs

notFound _ _ _ = do
    return $ responseLBS status404 [("Content-type", "text/html")] $ "404 - File Not Found"