Commit b5892ef5 authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

runs.

parent 71a09434
......@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: 130568e8906ba78e7d3abb16ae293016701085b7a7df3d7355a3220b9de36158
-- hash: af9d13db555581390fe9273f4721790b8f73e3e1653aa95d62e7653899693c62
name: Cirkeltrek
version: 0.0.0
......@@ -20,10 +20,15 @@ library
hs-source-dirs:
src
build-depends:
base
aeson
, base
, classy-prelude
, classy-prelude-yesod
, esqueleto
, fast-logger
, file-embed
, http-client
, http-client-tls
, monad-logger
, persistent
, persistent-postgresql
......@@ -33,10 +38,13 @@ library
, wai-extra
, wai-logger
, warp
, yaml
, yesod
, yesod-auth
, yesod-auth-hashdb
, yesod-core
, yesod-form
, yesod-static
default-language: Haskell2010
executable Cirkeltrek
......@@ -48,10 +56,15 @@ executable Cirkeltrek
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
Cirkeltrek
, aeson
, base
, classy-prelude
, classy-prelude-yesod
, esqueleto
, fast-logger
, file-embed
, http-client
, http-client-tls
, monad-logger
, persistent
, persistent-postgresql
......@@ -61,8 +74,11 @@ executable Cirkeltrek
, wai-extra
, wai-logger
, warp
, yaml
, yesod
, yesod-auth
, yesod-auth-hashdb
, yesod-core
, yesod-form
, yesod-static
default-language: Haskell2010
[email protected]:1523102271
\ No newline at end of file
static-dir: "static"
app-host: "*4"
app-port: 3000
development: false
database-conf:
user: "ibnu"
password: "jaran"
host: "localhost"
port: 5432
database: "cirkeltrek"
poolsize: 10
......@@ -3,18 +3,26 @@ version: "0.0.0"
dependencies:
- base
- aeson
- classy-prelude
- classy-prelude-yesod
- esqueleto
- fast-logger
- file-embed
- http-client
- http-client-tls
- monad-logger
- persistent
- persistent-template
- persistent-postgresql
- template-haskell
- yaml
- yesod
- yesod-auth
- yesod-auth-hashdb
- yesod-core
- yesod-form
- yesod-static
- wai
- wai-extra
- wai-logger
......
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Application where
import Control.Monad
import Control.Monad.Logger
import Database.Persist.Postgresql
import Foundation
import Language.Haskell.TH.Syntax
import Network.HTTP.Client.TLS
import Network.Wai.Handler.Warp
import System.Log.FastLogger
import Yesod.Core
import Yesod.Default.Config2
import Yesod.Static
import Home
import Settings (ApplicationSettings (..))
import Settings (ApplicationSettings (..),
configSettingsYmlValue)
mkYesodDispatch "App" resourcesApp
makeFoundation :: ApplicationSettings -> IO App
makeFoundation appSettings = do
appHttpManager <- getGlobalManager
appLogger <- newStdoutLoggerSet defaultBufSize >>= makeYesodLogger
appStatic <-
(if appMutableStatic appSettings
then staticDevel
else static)
(appStaticDir appSettings)
let mkFoundation appConnectionPool = App {..}
tempFoundation =
mkFoundation $ error "Connection pool forced in tempFoundation"
logFunc = messageLoggerSource tempFoundation appLogger
pool <-
flip runLoggingT logFunc $
createPostgresqlPool
(pgConnStr $ appDatabaseConf appSettings)
(pgPoolSize $ appDatabaseConf appSettings)
return $ mkFoundation pool
warpSettings :: App -> Settings
warpSettings app =
setPort (appPort $ appSettings app) $
......@@ -41,6 +69,7 @@ makeApplication app = do
newMain :: IO ()
newMain = do
let app = undefined
settings <- loadYamlSettingsArgs [configSettingsYmlValue] useEnv
app <- makeFoundation settings
commonapp <- makeApplication app
runSettings (warpSettings app) commonapp
......@@ -6,8 +6,10 @@
module Foundation where
import Database.Persist.Sql
import Network.HTTP.Client
import Yesod.Core
import Yesod.Core.Types
import Yesod.Static
import Settings
......@@ -15,6 +17,8 @@ data App = App
{ appSettings :: ApplicationSettings
, appConnectionPool :: ConnectionPool
, appLogger :: Logger
, appStatic :: Static
, appHttpManager :: Manager
}
mkYesodData
......
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Settings where
import ClassyPrelude.Yesod
import Control.Exception as Exception
import Data.Aeson
import Data.FileEmbed
import Data.Yaml
import Database.Persist.Postgresql
import Language.Haskell.TH.Syntax
import Network.Wai.Handler.Warp
import Yesod.Default.Config2
data ApplicationSettings = ApplicationSettings
{ appStaticDir :: String
, appRoot :: Maybe Text
, appHost :: HostPreference
, appDatabaseConf :: PostgresConf
, appPort :: Int
, appReloadTemplate :: Bool
, appMutableStatic :: Bool
, appSkipCombining :: Bool
, appDetailedRequestLogging :: Bool
}
instance FromJSON ApplicationSettings where
parseJSON =
withObject "ApplicationSettings" $ \ob -> do
let defEnv = True
appStaticDir <- ob .: "static-dir"
appRoot <- ob .:? "app-root"
appHost <- fromString <$> ob .: "app-host"
appDatabaseConf <- ob .: "database-conf"
appPort <- ob .: "app-port"
dev <- ob .: "development" .!= defEnv
appReloadTemplate <- ob .:? "reload-template" .!= dev
appMutableStatic <- ob .:? "mutable-static" .!= dev
appSkipCombining <- ob .:? "skip-combining" .!= dev
appDetailedRequestLogging <- ob .:? "detailed-req-log" .!= dev
return ApplicationSettings {..}
configSettingsYmlBS :: ByteString
configSettingsYmlBS = $(embedFile configSettingsYml)
configSettingsYmlValue :: Value
configSettingsYmlValue = either Exception.throw id $ decodeEither' configSettingsYmlBS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment