@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- | This module defines a sever-side handler that lets you serve static files.
23--
34-- - 'serveDirectory' lets you serve anything that lives under a particular
@@ -6,10 +7,13 @@ module Servant.Utils.StaticFiles (
67 serveDirectory,
78 ) where
89
9−import Filesystem.Path.CurrentOS (decodeString)
10+import Data.List (isSuffixOf)
1011import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
1112import Servant.API.Raw (Raw)
1213import Servant.Server (Server)
14+#if !MIN_VERSION_wai_app_static(3,1,0)
15+import Filesystem.Path.CurrentOS (decodeString)
16+#endif
1317
1418-- | Serve anything under the specified directory as a 'Raw' endpoint.
1519--
@@ -32,5 +36,10 @@ import Servant.Server (Server)
3236-- handler in the last position, because /servant/ will try to match the handlers
3337-- in order.
3438serveDirectory :: FilePath -> Server Raw
35−serveDirectory documentRoot =
36− staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))
39+serveDirectory =
40+#if MIN_VERSION_wai_app_static(3,1,0)
41+ staticApp . defaultFileServerSettings . mkSuff
42+#else
43+ staticApp . defaultFileServerSettings . decodeString . mkSuff
44+#endif
45+ where mkSuff x = if "/" `isSuffixOf` x then x else x ++ "/"