module Main where

import Control.Concurrent
import Control.Monad
import HAppS.Server
import HAppS.Server.Extra
import HAppS.Template.HSP.Handle
import HSPForm
import System.Environment
import FormPage


main :: IO ()
main = 
      do store <- newStore
         eConf <- liftM parseConfig getArgs
         let conf = case eConf of
                     Left e -> error (unlines e)
                     Right c -> c { validator = Just wdgHTMLValidator }
         tid <- forkIO $ simpleHTTP conf $ impl store
         putStrLn "running..."
         waitForTermination
         killThread tid
         destroyStore store

impl :: Store -> [ServerPart Response]
impl store =
    [ runHSPHandle "." "objfiles" store $ multi
      handleDate
    , debug404
    ]

