Use filepath to add trailing path separator

This commit is contained in:
Ilya Smelkov 2015-05-16 01:03:48 +03:00
parent c41267811e
commit 7e14eeafe9
2 changed files with 5 additions and 5 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

@ -7,7 +7,7 @@ module Servant.Utils.StaticFiles (
serveDirectory, serveDirectory,
) where ) where
import Data.List (isSuffixOf) 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)
@ -38,8 +38,7 @@ import Filesystem.Path.CurrentOS (decodeString)
serveDirectory :: FilePath -> Server Raw serveDirectory :: FilePath -> Server Raw
serveDirectory = serveDirectory =
#if MIN_VERSION_wai_app_static(3,1,0) #if MIN_VERSION_wai_app_static(3,1,0)
staticApp . defaultFileServerSettings . mkSuff staticApp . defaultFileServerSettings . addTrailingPathSeparator
#else #else
staticApp . defaultFileServerSettings . decodeString . mkSuff staticApp . defaultFileServerSettings . decodeString . addTrailingPathSeparator
#endif #endif
where mkSuff x = if "/" `isSuffixOf` x then x else x ++ "/"