on master help sign in
Merge pull request #82 from triplepointfive/drop-system-filepath
763928cJulian Arni
servant-server/servant-server.cabal+2−1
@@ -53,10 +53,11 @@ library
53 , split >= 0.2 && < 0.3
53 , split >= 0.2 && < 0.3
54 , string-conversions >= 0.3 && < 0.4
54 , string-conversions >= 0.3 && < 0.4
55 , system-filepath >= 0.4 && < 0.5
55 , system-filepath >= 0.4 && < 0.5
56+ , filepath >= 1
56 , text >= 1.2 && < 1.3
57 , text >= 1.2 && < 1.3
57 , transformers >= 0.3 && < 0.5
58 , transformers >= 0.3 && < 0.5
58 , wai >= 3.0 && < 3.1
59 , wai >= 3.0 && < 3.1
59− , wai-app-static >= 3.0 && < 3.1
60+ , wai-app-static >= 3.0 && < 3.2
60 , warp >= 3.0 && < 3.1
61 , warp >= 3.0 && < 3.1
61 hs-source-dirs: src
62 hs-source-dirs: src
62 default-language: Haskell2010
63 default-language: Haskell2010
servant-server/src/Servant/Utils/StaticFiles.hs+11−3
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- | This module defines a sever-side handler that lets you serve static files.
2-- | This module defines a sever-side handler that lets you serve static files.
2--
3--
3-- - 'serveDirectory' lets you serve anything that lives under a particular
4-- - 'serveDirectory' lets you serve anything that lives under a particular
@@ -6,10 +7,13 @@ module Servant.Utils.StaticFiles (
6 serveDirectory,
7 serveDirectory,
7 ) where
8 ) where
8
9
9−import Filesystem.Path.CurrentOS (decodeString)
10+import System.FilePath (addTrailingPathSeparator)
10import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
11import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
11import Servant.API.Raw (Raw)
12import Servant.API.Raw (Raw)
12import Servant.Server (Server)
13import Servant.Server (Server)
14+#if !MIN_VERSION_wai_app_static(3,1,0)
15+import Filesystem.Path.CurrentOS (decodeString)
16+#endif
13
17
14-- | Serve anything under the specified directory as a 'Raw' endpoint.
18-- | Serve anything under the specified directory as a 'Raw' endpoint.
15--
19--
@@ -32,5 +36,9 @@ import Servant.Server (Server)
32-- handler in the last position, because /servant/ will try to match the handlers
36-- handler in the last position, because /servant/ will try to match the handlers
33-- in order.
37-- in order.
34serveDirectory :: FilePath -> Server Raw
38serveDirectory :: FilePath -> Server Raw
35−serveDirectory documentRoot =
39+serveDirectory =
40+#if MIN_VERSION_wai_app_static(3,1,0)
41+ staticApp . defaultFileServerSettings . addTrailingPathSeparator
42+#else
36− staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))
43+ staticApp . defaultFileServerSettings . decodeString . addTrailingPathSeparator
44+#endif