on master help sign in
Move warp-static into wai-app-static
commitab1ed48c295b974586fc07b3082f6164503883e9 authorMichael Snoyman <michael@snoyman.com> dateFri 21 Mar 2014, 14:11 (13 years ago) parent7fdd702
3 files changed+71−3
wai-app-static/app/warp-static.hs+53 wai-app-static/wai-app-static.cabal+15−1 warp-static/warp-static.cabal+3−2
wai-app-static/app/warp-static.hsnew file+53
@@ -0,0 +1,53 @@
1+{-# LANGUAGE DeriveDataTypeable, RecordWildCards #-}
2+import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
3+import Network.Wai.Handler.Warp
4+ ( runSettings, defaultSettings, settingsHost, settingsPort
5+ )
6+import System.Console.CmdArgs hiding (def)
7+import Text.Printf (printf)
8+import System.Directory (canonicalizePath)
9+import Control.Monad (unless)
10+import Network.Wai.Middleware.Autohead
11+import Network.Wai.Middleware.RequestLogger (logStdout)
12+import Network.Wai.Middleware.Gzip
13+import qualified Data.Map as Map
14+import qualified Data.ByteString.Char8 as S8
15+import Control.Arrow ((***))
16+import Data.Text (pack)
17+import Data.String (fromString)
18+import Network.Mime (defaultMimeMap, mimeByExt, defaultMimeType)
19+import WaiAppStatic.Types (ssIndices, toPiece, ssGetMimeType, fileName, fromPiece)
20+import Data.Maybe (mapMaybe)
21+
22+data Args = Args
23+ { docroot :: FilePath
24+ , index :: [FilePath]
25+ , port :: Int
26+ , noindex :: Bool
27+ , quiet :: Bool
28+ , verbose :: Bool
29+ , mime :: [(String, String)]
30+ , host :: String
31+ }
32+ deriving (Show, Data, Typeable)
33+
34+defaultArgs :: Args
35+defaultArgs = Args "." ["index.html", "index.htm"] 3000 False False False [] "*"
36+
37+main :: IO ()
38+main = do
39+ Args {..} <- cmdArgs defaultArgs
40+ let mime' = map (pack *** S8.pack) mime
41+ let mimeMap = Map.fromList mime' `Map.union` defaultMimeMap
42+ docroot' <- canonicalizePath docroot
43+ unless quiet $ printf "Serving directory %s on port %d with %s index files.\n" docroot' port (if noindex then "no" else show index)
44+ let middle = gzip def { gzipFiles = GzipCompress }
45+ . (if verbose then logStdout else id)
46+ . autohead
47+ runSettings defaultSettings
48+ { settingsPort = port
49+ , settingsHost = fromString host
50+ } $ middle $ staticApp (defaultFileServerSettings $ fromString docroot)
51+ { ssIndices = if noindex then [] else mapMaybe (toPiece . pack) index
52+ , ssGetMimeType = return . mimeByExt mimeMap defaultMimeType . fromPiece . fileName
53+ }
wai-app-static/wai-app-static.cabal+15−1
@@ -1,5 +1,5 @@
11name: wai-app-static
2−version: 2.0.0.4
2+version: 2.0.0.5
33license: MIT
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>
@@ -65,6 +65,20 @@ library
6565 if flag(print)
6666 cpp-options: -DPRINT
6767
68+Executable warp
69+ Main-is: warp-static.hs
70+ hs-source-dirs: app
71+ Build-depends: base >= 4 && < 5
72+ , warp >= 2.0 && < 2.2
73+ , wai-app-static >= 2.0 && < 2.1
74+ , wai-extra >= 2.0 && < 2.2
75+ , cmdargs >= 0.6.7
76+ , directory >= 1.0
77+ , containers >= 0.2
78+ , bytestring >= 0.9.1.4
79+ , text >= 0.7
80+ , mime-types >= 0.1 && < 0.2
81+
6882test-suite runtests
6983 hs-source-dirs: test
7084 main-is: ../tests.hs
warp-static/warp-static.cabal+3−2
@@ -1,6 +1,7 @@
11Name: warp-static
2−Version: 2.0.1
3−Synopsis: Static file server based on Warp and wai-app-static
2+Version: 2.0.1.1
3+Synopsis: Static file server based on Warp and wai-app-static (deprecated)
4+description: This executable is now provided by wai-app-static.
45Homepage: http://github.com/yesodweb/wai
56License: MIT
67License-file: LICENSE