Merge pull request #82 from triplepointfive/drop-system-filepath

Add support for wai-app-static-3.1.0
This commit is contained in:
Julian Arni 2015-05-18 12:55:40 +02:00
commit 763928cd66
2 changed files with 13 additions and 4 deletions

View file

@ -53,10 +53,11 @@ library
, split >= 0.2 && < 0.3 , split >= 0.2 && < 0.3
, string-conversions >= 0.3 && < 0.4 , string-conversions >= 0.3 && < 0.4
, system-filepath >= 0.4 && < 0.5 , system-filepath >= 0.4 && < 0.5
, filepath >= 1
, text >= 1.2 && < 1.3 , text >= 1.2 && < 1.3
, transformers >= 0.3 && < 0.5 , transformers >= 0.3 && < 0.5
, wai >= 3.0 && < 3.1 , wai >= 3.0 && < 3.1
, wai-app-static >= 3.0 && < 3.1 , wai-app-static >= 3.0 && < 3.2
, warp >= 3.0 && < 3.1 , warp >= 3.0 && < 3.1
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010

View file

@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
-- | This module defines a sever-side handler that lets you serve static files. -- | This module defines a sever-side handler that lets you serve static files.
-- --
-- - 'serveDirectory' lets you serve anything that lives under a particular -- - 'serveDirectory' lets you serve anything that lives under a particular
@ -6,10 +7,13 @@ module Servant.Utils.StaticFiles (
serveDirectory, serveDirectory,
) where ) where
import Filesystem.Path.CurrentOS (decodeString) import System.FilePath (addTrailingPathSeparator)
import Network.Wai.Application.Static (staticApp, defaultFileServerSettings) import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
import Servant.API.Raw (Raw) import Servant.API.Raw (Raw)
import Servant.Server (Server) import Servant.Server (Server)
#if !MIN_VERSION_wai_app_static(3,1,0)
import Filesystem.Path.CurrentOS (decodeString)
#endif
-- | Serve anything under the specified directory as a 'Raw' endpoint. -- | Serve anything under the specified directory as a 'Raw' endpoint.
-- --
@ -32,5 +36,9 @@ import Servant.Server (Server)
-- handler in the last position, because /servant/ will try to match the handlers -- handler in the last position, because /servant/ will try to match the handlers
-- in order. -- in order.
serveDirectory :: FilePath -> Server Raw serveDirectory :: FilePath -> Server Raw
serveDirectory documentRoot = serveDirectory =
staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/"))) #if MIN_VERSION_wai_app_static(3,1,0)
staticApp . defaultFileServerSettings . addTrailingPathSeparator
#else
staticApp . defaultFileServerSettings . decodeString . addTrailingPathSeparator
#endif