{-# LANGUAGE
    OverloadedStrings
  , FlexibleContexts
  #-}


module Application where

import Template.Main (htmlLight, page)
import Application.Types (MonadApp)
import Network.Wai.Trans (ApplicationT, MiddlewareT)
import Network.Wai (pathInfo)
import Network.Wai.Middleware.ContentType
import Network.Wai.Middleware.Verbs (get)
import Network.HTTP.Types (status200, status404)
import Web.Page.Lucid (template)
import Web.Routes.Nested (RouterT, route, matchHere, match, matchAny, action)
import Lucid


server :: MonadApp m => MiddlewareT m
server = route routes
  where
    routes :: MonadApp m => RouterT (MiddlewareT m) sec m ()
    routes = do
      matchHere $ action $ get $ htmlLight status200 $ template page $ p_ "Sup!"
      matchAny  $ action $ get $ htmlLight status404 $ template page $ p_ "404 d:"


defApp :: MonadApp m => ApplicationT m
defApp _ respond = respond $ textOnly "404 d:" status404 []
