on master help sign in
canonicalizePath
97ded72Michael Snoyman
warp-static.cabal+2−1
@@ -1,5 +1,5 @@
1Name: warp-static
1Name: warp-static
2−Version: 0.0.0
2+Version: 0.0.1
3Synopsis: Static file server based on Warp and wai-app-static
3Synopsis: Static file server based on Warp and wai-app-static
4Homepage: http://github.com/snoyberg/warp-static
4Homepage: http://github.com/snoyberg/warp-static
5License: BSD3
5License: BSD3
@@ -17,3 +17,4 @@ Executable warp
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
19 , cmdargs >= 0.6.7 && < 0.7
20+ , directory >= 1.0 && < 1.2
warp.hs+6−2
@@ -6,22 +6,26 @@ import Network.Wai.Handler.Warp (run)
6import System.Environment (getArgs)
6import System.Environment (getArgs)
7import System.Console.CmdArgs
7import System.Console.CmdArgs
8import Text.Printf (printf)
8import Text.Printf (printf)
9+import System.Directory (canonicalizePath)
10+import Control.Monad (unless)
9
11
10data Args = Args
12data Args = Args
11 { docroot :: FilePath
13 { docroot :: FilePath
12 , index :: [FilePath]
14 , index :: [FilePath]
13 , port :: Int
15 , port :: Int
14 , noindex :: Bool
16 , noindex :: Bool
17+ , quiet :: Bool
15 }
18 }
16 deriving (Show, Data, Typeable)
19 deriving (Show, Data, Typeable)
17
20
18−defaultArgs = Args "." ["index.html", "index.htm"] 3000 False
21+defaultArgs = Args "." ["index.html", "index.htm"] 3000 False False
19
22
20main :: IO ()
23main :: IO ()
21main = do
24main = do
22 Args {..} <- cmdArgs defaultArgs
25 Args {..} <- cmdArgs defaultArgs
26+ docroot' <- canonicalizePath docroot
23 args <- getArgs
27 args <- getArgs
24− printf "Serving directory %s on port %d with %s index files.\n" docroot port (if noindex then "no" else show index)
28+ unless quiet $ printf "Serving directory %s on port %d with %s index files.\n" docroot' port (if noindex then "no" else show index)
25 run port $ staticApp StaticSettings
29 run port $ staticApp StaticSettings
26 { ssFolder = docroot
30 { ssFolder = docroot
27 , ssIndices = if noindex then [] else index
31 , ssIndices = if noindex then [] else index