packages feed

snap-core-0.2.5: project_template/default/src/Main.hs

{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Control.Applicative
import           Snap.Types
import           Snap.Util.FileServe

import           Common

config :: AppConfig
config = AppConfig {
  templateDir = "templates",
  accessLog = Just "access.log",
  errorLog = Just "error.log"
}

main :: IO ()
main = do
    quickServer config site

site :: Snap ()
site =
    ifTop (writeBS "hello world") <|>
    route [ ("foo", writeBS "bar")
          , ("echo/:echoparam", echoHandler)
          ] <|>
    dir "static" (fileServe ".")

echoHandler :: Snap ()
echoHandler = do
    param <- getParam "echoparam"
    maybe (writeBS "must specify echo/param in URL")
          writeBS param