diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..c40af76 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,54 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TemplateHaskell #-} +module Main where + +import Data.Aeson +import GHC.Generics +import Network.Wai +import Network.Wai.Handler.Warp +import Servant +import HFlags +import System.Exit +import Control.Monad +import Data +import PhotoStore +import Control.Monad.IO.Class + +defineFlag "port" (8081 :: Int) "Port to serve on" +defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" +defineFlag "pending_path" ("" :: String) "Path to pending albums" +defineFlag "photos_path" ("" :: String) "Path to permanent albums" +$(return []) + +instance ToJSON Album + +type PhotoApi = "albums" :> Get '[JSON] [Album] + +config = Config + { pendingPath = flags_pending_path + , photosPath = flags_photos_path + } + +server :: Server PhotoApi +server = liftIO (getAlbums config) + +photoApi :: Proxy PhotoApi +photoApi = Proxy + +app :: Application +app = serve photoApi server + +port = 8081 +settings :: Settings +settings = setHost "*6" . setPort 8081 $ defaultSettings + +main :: IO () +main = do + $initHFlags "photos" + when (flags_pending_path == "") (die "--pending_path must be specified") + when (flags_photos_path == "") (die "--photos_path must be specified") + putStrLn $ "Starting server on port: " ++ (show port) + runSettings settings app |