on master help sign in
wai-app-static 0.3
commitd4952acae927456b45538582afeb23887dfce1ec authorMichael Snoyman <michael@snoyman.com> dateFri 22 Jul 2011, 11:28 (15 years ago) parentae101a0
2 files changed+12−8
warp-static.cabal+3−2 warp.hs+9−6
warp-static.cabal+3−2
@@ -1,5 +1,5 @@
11Name: warp-static
2−Version: 0.1.1
2+Version: 0.2.0
33Synopsis: Static file server based on Warp and wai-app-static
44Homepage: http://github.com/snoyberg/warp-static
55License: BSD3
@@ -15,9 +15,10 @@ Executable warp
1515 Main-is: warp.hs
1616 Build-depends: base >= 4 && < 5
1717 , warp >= 0.4 && < 0.5
18− , wai-app-static >= 0.1 && < 0.2
18+ , wai-app-static >= 0.3 && < 0.4
1919 , wai-extra >= 0.4 && < 0.5
2020 , cmdargs >= 0.6.7 && < 0.8
2121 , directory >= 1.0 && < 1.2
2222 , containers >= 0.2 && < 0.5
2323 , bytestring >= 0.9 && < 0.10
24+ , text < 1.0
warp.hs+9−6
@@ -2,6 +2,8 @@
22import Network.Wai.Application.Static
33 ( StaticSettings (..), staticApp, defaultMimeType, defaultListing
44 , defaultMimeTypes, mimeTypeByExt
5+ , defaultFileServerSettings, fileSystemLookup
6+ , fileName, toFilePath
57 )
68import Network.Wai.Handler.Warp (run)
79import System.Environment (getArgs)
@@ -14,7 +16,8 @@ import Network.Wai.Middleware.Debug
1416import Network.Wai.Middleware.Gzip
1517import qualified Data.Map as Map
1618import qualified Data.ByteString.Char8 as S8
17−import Control.Arrow (second)
19+import Control.Arrow ((***))
20+import Data.Text (pack, unpack)
1821
1922data Args = Args
2023 { docroot :: FilePath
@@ -32,7 +35,7 @@ defaultArgs = Args "." ["index.html", "index.htm"] 3000 False False False []
3235main :: IO ()
3336main = do
3437 Args {..} <- cmdArgs defaultArgs
35− let mime' = map (second S8.pack) mime
38+ let mime' = map (toFilePath *** S8.pack) mime
3639 let mimeMap = Map.fromList mime' `Map.union` defaultMimeTypes
3740 docroot' <- canonicalizePath docroot
3841 args <- getArgs
@@ -40,9 +43,9 @@ main = do
4043 let middle = gzip False
4144 . (if verbose then debug else id)
4245 . autohead
43− run port $ middle $ staticApp StaticSettings
44− { ssFolder = docroot
45− , ssIndices = if noindex then [] else index
46+ run port $ middle $ staticApp defaultFileServerSettings
47+ { ssFolder = fileSystemLookup $ toFilePath docroot
48+ , ssIndices = if noindex then [] else map pack index
4649 , ssListing = Just defaultListing
47− , ssGetMimeType = return . mimeTypeByExt mimeMap defaultMimeType
50+ , ssGetMimeType = return . mimeTypeByExt mimeMap defaultMimeType . fileName
4851 }