breve/Shortener/Common.hs

29 lines
835 B
Haskell
Raw Normal View History

2015-04-08 12:47:56 +02:00
{-# LANGUAGE MultiParamTypeClasses #-}
module Shortener.Common where
import Control.Applicative
2015-04-08 15:54:06 +02:00
import Text.Printf
import Data.String
import System.Environment
import Network.Wai.Handler.Warp
2015-04-08 12:47:56 +02:00
import Web.Simple
import Web.Simple.Templates
2015-04-08 13:55:36 +02:00
data AppSettings = AppSettings { }
2015-04-08 12:47:56 +02:00
2015-04-08 15:54:06 +02:00
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)
2015-04-08 12:47:56 +02:00
newAppSettings :: IO AppSettings
2015-04-08 13:55:36 +02:00
newAppSettings = return AppSettings
2015-04-08 12:47:56 +02:00
instance HasTemplates IO AppSettings where
defaultLayout = Just <$> getTemplate "layouts/main.html"