Compare commits
1 commit
1ea0aebdb7
...
3eff953def
Author | SHA1 | Date | |
---|---|---|---|
3eff953def |
3 changed files with 19 additions and 5 deletions
|
@ -24,6 +24,7 @@ dependencies:
|
|||
- containers
|
||||
- envy
|
||||
- lens
|
||||
- network-uri
|
||||
- openapi3
|
||||
- parsec
|
||||
- parsec-extra
|
||||
|
|
|
@ -25,6 +25,7 @@ import qualified Data.Text as T
|
|||
import Data.Typeable (Typeable)
|
||||
import Data.Version (showVersion)
|
||||
import GHC.Generics (Generic)
|
||||
import Network.URI
|
||||
import qualified Paths_tutor as PT
|
||||
import Servant
|
||||
import Servant.OpenApi (HasOpenApi (toOpenApi))
|
||||
|
@ -229,9 +230,12 @@ tutorServer config = status config :<|> searchCards (tutorDatabase config)
|
|||
prev Pagination.Page {Pagination.previous = Just p} = addHeader $ link "prev" $ uri (Just $ Pagination.limit p) (Just $ Pagination.offset p)
|
||||
prev _ = noHeader
|
||||
uri :: Maybe Int -> Maybe Int -> URI
|
||||
uri limit' offset' = linkURI $ safeLink api (Proxy :: Proxy SearchCards) q sortBy inCollection limit' offset'
|
||||
uri limit' offset' =
|
||||
-- TODO: Apply the generated relative URI to the requested absolute URI
|
||||
relativeTo
|
||||
(linkURI $ safeLink api (Proxy :: Proxy SearchCards) q sortBy inCollection limit' offset')
|
||||
(configuredBaseURI config)
|
||||
link :: T.Text -> URI -> T.Text
|
||||
-- TODO: Apply the generated relative URI to the requested absolute URI
|
||||
link rel uri = T.concat ["<", T.pack $ show uri, ">; rel=\"", rel, "\""]
|
||||
|
||||
docsServer :: Server DocsAPI
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
||||
module Tutor.Config (Config (..), defaultConfig) where
|
||||
module Tutor.Config (Config (..), defaultConfig, configuredBaseURI) where
|
||||
|
||||
import GHC.Generics
|
||||
import Network.URI
|
||||
import System.Envy
|
||||
|
||||
data Config = Config
|
||||
{ tutorPort :: Int,
|
||||
tutorDatabase :: FilePath,
|
||||
tutorStatic :: FilePath
|
||||
tutorStatic :: FilePath,
|
||||
tutorBaseUrl :: Maybe String
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
|
@ -16,7 +18,14 @@ defaultConfig =
|
|||
Config
|
||||
{ tutorPort = 8000,
|
||||
tutorDatabase = "tutor.db",
|
||||
tutorStatic = "www/public"
|
||||
tutorStatic = "www/public",
|
||||
tutorBaseUrl = Nothing
|
||||
}
|
||||
|
||||
configuredBaseURI :: Config -> URI
|
||||
configuredBaseURI config =
|
||||
case tutorBaseUrl config >>= parseURI of
|
||||
Just uri -> uri
|
||||
Nothing -> URI "http:" (Just $ URIAuth "" "localhost" (":" ++ show (tutorPort config))) "/" "" ""
|
||||
|
||||
instance FromEnv Config
|
||||
|
|
Loading…
Reference in a new issue