on master help sign in
cmdargs
ecb2a7fMichael Snoyman
LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c)2011, Michael Snoyman
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Michael Snoyman nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
warp-static.cabal+1
@@ -16,3 +16,4 @@ Executable warp
16 Build-depends: base >= 4 && < 5
16 Build-depends: base >= 4 && < 5
17 , warp >= 0.3 && < 0.4
17 , warp >= 0.3 && < 0.4
18 , wai-app-static >= 0.0 && < 0.1
18 , wai-app-static >= 0.0 && < 0.1
19+ , cmdargs >= 0.6.7 && < 0.7
warp.hs+15−8
@@ -1,21 +1,28 @@
1+{-# LANGUAGE DeriveDataTypeable, RecordWildCards #-}
1import Network.Wai.Application.Static
2import Network.Wai.Application.Static
2 ( StaticSettings (..), staticApp, defaultMimeTypeByExt, defaultListing
3 ( StaticSettings (..), staticApp, defaultMimeTypeByExt, defaultListing
3 )
4 )
4import Network.Wai.Handler.Warp (run)
5import Network.Wai.Handler.Warp (run)
5import System.Environment (getArgs)
6import System.Environment (getArgs)
7+import System.Console.CmdArgs
8+
9+data Args = Args
10+ { docroot :: FilePath
11+ , index :: [FilePath]
12+ , port :: Int
13+ , noindex :: Bool
14+ }
15+ deriving (Show, Data, Typeable)
16+
17+defaultArgs = Args "." ["index.html", "index.htm"] 3000 False
6
18
7main :: IO ()
19main :: IO ()
8main = do
20main = do
21+ Args {..} <- cmdArgs defaultArgs
9 args <- getArgs
22 args <- getArgs
10− (folder, port) <- return $
11− case args of
12− [] -> (".", 3000)
13− [f] -> (f, 3000)
14− [f, p] -> (f, read p)
15− _ -> error "Usage: warp-static [root [port]]"
16 run port $ staticApp StaticSettings
23 run port $ staticApp StaticSettings
17− { ssFolder = folder
24+ { ssFolder = docroot
18− , ssIndices = ["index.html", "index.htm"]
25+ , ssIndices = if noindex then [] else index
19 , ssListing = Just defaultListing
26 , ssListing = Just defaultListing
20 , ssGetMimeType = return . defaultMimeTypeByExt
27 , ssGetMimeType = return . defaultMimeTypeByExt
21 }
28 }