{-# LANGUAGE MultiParamTypeClasses #-} module Shortener.Common where import Control.Applicative import Text.Printf import Data.String import System.Environment import Network.Wai.Handler.Warp import Web.Simple import Web.Simple.Templates data AppSettings = AppSettings { } serverSettings :: IO (String, Settings) serverSettings = do port <- maybe 3000 read <$> lookupEnv "PORT" host <- maybe "127.0.0.1" id <$> lookupEnv "ADDRESS" let opts = setPort port $ setHost (fromString host) defaultSettings url = if port == 80 then printf "http://%s/" host else printf "http://%s:%d/" host port return (url, opts) newAppSettings :: IO AppSettings newAppSettings = return AppSettings instance HasTemplates IO AppSettings where defaultLayout = Just <$> getTemplate "layouts/main.html"