Name the main module "Main" as required

This commit is contained in:
Joe Nelson
2016-02-29 14:50:44 -08:00
parent 088df7e6be
commit e315ad99b4
4 changed files with 29 additions and 31 deletions
-1
View File
@@ -145,7 +145,6 @@ Test-Suite spec
, PostgREST.Auth
, PostgREST.Config
, PostgREST.Error
, PostgREST.Main
, PostgREST.Middleware
, PostgREST.Parsers
, PostgREST.DbStructure
+27 -8
View File
@@ -3,7 +3,7 @@
{-# LANGUAGE TupleSections #-}
--module PostgREST.App where
module PostgREST.App (
app
postgrest
) where
import Control.Applicative
@@ -18,6 +18,9 @@ import Data.String.Conversions (cs)
import Data.Text (Text, replace, strip)
import Data.Tree
import qualified Hasql.Pool as P
import qualified Hasql.Transaction as HT
import Text.Parsec.Error
import Text.ParserCombinators.Parsec (parse)
@@ -26,25 +29,26 @@ import Network.HTTP.Types.Header
import Network.HTTP.Types.Status
import Network.HTTP.Types.URI (parseSimpleQuery)
import Network.Wai
import Network.Wai.Middleware.RequestLogger (logStdout)
import Data.Aeson
import Data.Aeson.Types (emptyArray)
import Data.Monoid
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Data.Vector as V
import qualified Hasql.Transaction as H
import PostgREST.Config (AppConfig (..))
import PostgREST.Parsers
import PostgREST.DbStructure
import PostgREST.RangeQuery
import PostgREST.ApiRequest (ApiRequest(..), ContentType(..)
, Action(..), Target(..)
, PreferRepresentation (..)
, userApiRequest)
import PostgREST.Types
import PostgREST.Auth (tokenJWT)
import PostgREST.Error (errResponse)
import PostgREST.Config (AppConfig (..))
import PostgREST.DbStructure
import PostgREST.Error (errResponse, pgErrResponse)
import PostgREST.Parsers
import PostgREST.RangeQuery
import PostgREST.Middleware
import PostgREST.QueryBuilder ( callProc
, addJoinConditions
, sourceCTEName
@@ -55,9 +59,24 @@ import PostgREST.QueryBuilder ( callProc
, createWriteStatement
, ResultsWithCount
)
import PostgREST.Types
import Prelude
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
postgrest conf dbStructure pool =
let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in
middle $ \ req respond -> do
time <- getPOSIXTime
body <- strictRequestBody req
let handleReq = runWithClaims conf time (app dbStructure conf body) req
resp <- either pgErrResponse id <$> P.use pool
(HT.run handleReq HT.ReadCommitted HT.Write)
respond resp
app :: DbStructure -> AppConfig -> RequestBody -> Request -> H.Transaction Response
app dbStructure conf reqBody req =
let
+1 -21
View File
@@ -1,6 +1,6 @@
{-# LANGUAGE CPP #-}
module PostgREST.Main where
module Main where
import PostgREST.App
@@ -9,23 +9,16 @@ import PostgREST.Config (AppConfig (..),
prettyVersion,
readOptions)
import PostgREST.DbStructure
import PostgREST.Error (pgErrResponse)
import PostgREST.Middleware
import PostgREST.Types (DbStructure)
import Control.Monad
import Data.Monoid ((<>))
import Data.String.Conversions (cs)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Hasql.Query as H
import qualified Hasql.Session as H
import qualified Hasql.Transaction as HT
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
import qualified Hasql.Pool as P
import Network.Wai
import Network.Wai.Handler.Warp
import Network.Wai.Middleware.RequestLogger (logStdout)
import System.IO (BufferMode (..),
hSetBuffering, stderr,
stdin, stdout)
@@ -82,16 +75,3 @@ main = do
let dbStructure = either (error.show) id result
runSettings appSettings $ postgrest conf dbStructure pool
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
postgrest conf dbStructure pool =
let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in
middle $ \ req respond -> do
time <- getPOSIXTime
body <- strictRequestBody req
let handleReq = runWithClaims conf time (app dbStructure conf body) req
resp <- either pgErrResponse id <$> P.use pool
(HT.run handleReq HT.ReadCommitted HT.Write)
respond resp
+1 -1
View File
@@ -6,7 +6,7 @@ import SpecHelper
import qualified Hasql.Pool as P
import PostgREST.DbStructure (getDbStructure)
import PostgREST.Main (postgrest)
import PostgREST.App (postgrest)
import Data.String.Conversions (cs)
import qualified Feature.AuthSpec