servius 1.0.0.2 → 1.1.0
raw patch · 2 files changed
+17/−19 lines, 2 filesdep +mime-typesdep ~hamletdep ~waidep ~wai-app-static
Dependencies added: mime-types
Dependency ranges changed: hamlet, wai, wai-app-static, wai-extra, warp
Files
- servius.cabal +7/−6
- servius.hs +10/−13
servius.cabal view
@@ -1,5 +1,5 @@ Name: servius-Version: 1.0.0.2+Version: 1.1.0 Synopsis: Serve Shakespearean templates via Warp Homepage: http://github.com/yesodweb/hamlet License: MIT@@ -15,9 +15,9 @@ Executable servius Main-is: servius.hs Build-depends: base >= 4 && < 5- , warp >= 1.2 && < 1.3- , wai-app-static >= 1.2 && < 1.3- , wai-extra >= 1.2 && < 1.3+ , warp >= 1.3 && < 1.4+ , wai-app-static >= 1.3 && < 1.4+ , wai-extra >= 1.3 && < 1.4 , cmdargs >= 0.6.7 , directory >= 1.0 , containers >= 0.2@@ -26,10 +26,11 @@ , blaze-builder , blaze-html >= 0.5 && < 0.6 , http-types- , hamlet >= 1.0 && < 1.1+ , hamlet >= 1.1 && < 1.2 , shakespeare-css >= 1.0 && < 1.1 , transformers- , wai >= 1.2 && < 1.3+ , wai >= 1.3 && < 1.4+ , mime-types >= 0.1 && < 0.2 source-repository head type: git
servius.hs view
@@ -1,11 +1,6 @@ {-# LANGUAGE DeriveDataTypeable, RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}-import Network.Wai.Application.Static- ( StaticSettings (..), staticApp, defaultMimeType, defaultListing- , defaultMimeTypes, mimeTypeByExt- , defaultFileServerSettings, fileSystemLookup- , fileName, toFilePath- )+import Network.Wai.Application.Static (staticApp, defaultFileServerSettings) import Network.Wai.Handler.Warp (run) import System.Console.CmdArgs hiding (def) import Text.Printf (printf)@@ -30,6 +25,10 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtmlBuilder) import qualified Data.Text.Lazy as TL import Blaze.ByteString.Builder.Char.Utf8 (fromLazyText)+import Network.Mime (defaultMimeMap, mimeByExt, defaultMimeType)+import WaiAppStatic.Types (ssIndices, toPiece, ssGetMimeType, fileName, fromPiece)+import Data.String (fromString)+import Data.Maybe (mapMaybe) data Args = Args { docroot :: FilePath@@ -48,19 +47,17 @@ main :: IO () main = do Args {..} <- cmdArgs defaultArgs- let mime' = map (toFilePath *** S8.pack) mime- let mimeMap = Map.fromList mime' `Map.union` defaultMimeTypes+ let mime' = map (pack *** S8.pack) mime+ let mimeMap = Map.fromList mime' `Map.union` defaultMimeMap docroot' <- canonicalizePath docroot unless quiet $ printf "Serving directory %s on port %d with %s index files.\n" docroot' port (if noindex then "no" else show index) let middle = gzip def . (if verbose then logStdoutDev else id) . autohead . shake docroot- run port $ middle $ staticApp defaultFileServerSettings- { ssFolder = fileSystemLookup $ toFilePath docroot- , ssIndices = if noindex then [] else map pack index- , ssListing = Just defaultListing- , ssGetMimeType = return . mimeTypeByExt mimeMap defaultMimeType . fileName+ run port $ middle $ staticApp (defaultFileServerSettings $ fromString docroot)+ { ssIndices = if noindex then [] else mapMaybe (toPiece . pack) index+ , ssGetMimeType = return . mimeByExt mimeMap defaultMimeType . fromPiece . fileName } shake :: FilePath -> Middleware