packages feed

seacat 1.0.0.0 → 1.0.0.1

raw patch · 3 files changed

+3/−71 lines, 3 filesdep +web-routes-wai

Dependencies added: web-routes-wai

Files

seacat.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             1.0.0.0+version:             1.0.0.1  -- A short (one-line) description of the package. synopsis:            Small web framework using Warp and WAI@@ -68,7 +68,6 @@   other-modules:       Web.Seacat.Database                      , Web.Seacat.Server                      , Web.Seacat.RequestHandler.Types-                     , Web.Seacat.Router      ghc-options: -Wall   @@ -102,6 +101,7 @@                      , wai-middleware-static >=0.6 && <0.7                      , warp >=3.0 && <3.1                      , web-routes >=0.27 && <0.28+                     , web-routes-wai >= 0.24 && <0.25    -- Directories containing source files.   hs-source-dirs:      src
− src/Web/Seacat/Router.hs
@@ -1,68 +0,0 @@--- |This is a port of (what I use of) Web.Routes.Wai to Wai 3.0, as I--- got tired of waiting for upstream to update.-module Web.Seacat.Router ( handleWai-                         , handleWai_-                         , handleWaiError ) where--import Data.Text (Text, append)-import Data.Text.Encoding (decodeUtf8)-import Network.HTTP.Types (status404)-import Network.Wai (Application, rawPathInfo , responseLBS)-import Web.Routes.PathInfo (PathInfo(..), fromPathInfo, toPathInfoParams, stripOverlapBS)--import qualified Data.ByteString.Char8 as C-import qualified Data.ByteString.Lazy.Char8 as L---- | A URL pretty printer. This is like MkUrl from--- Web.Seacat.RequestHandler.Types, except that it uses a (Text, Maybe--- Text) to stick close to web-routes-wai, easing migration back when--- it is finally updated.-type MkUrl r = r -> [(Text, Maybe Text)] -> Text---- | A URL parser. This turns a URL into either an error message, or a--- parsed URL type, suitable for giving to the routing function.-type FromUrl r = C.ByteString -> Either String r---- | A routing function type.--- --- Takes a URL printing function and a parsed URL and returns the--- appropriate Application for that URL.-type RoutingFunction r = MkUrl r -> r -> Application---- |Convert a routing function into an Application by using PathInfo.-handleWai :: PathInfo r-          => C.ByteString -- ^ The application web route-          -> RoutingFunction r-          -> Application-handleWai = handleWai_ toPathInfoParams fromPathInfo------------------------------- |Convert a URL parser, a URL printer, and a routing function into--- an Application. If the URL parsing fails, this returns a 404.-handleWai_ :: MkUrl r-           -> FromUrl r-           -> C.ByteString -- ^ The application web route-           -> RoutingFunction r-           -> Application-handleWai_ fromUrl toUrl approot handler =-    handleWaiError fromUrl toUrl approot handleError handler-    where-      handleError parseError  = \wreq receiver -> handleError' parseError wreq >>= receiver-      handleError' parseError = \_ -> return $ responseLBS status404 [] (L.pack parseError)------------------------------- |Convert a URL parser, a URL printer, an error handling function,--- and a routing function into an application.-handleWaiError :: MkUrl r-               -> FromUrl r-               -> C.ByteString -- ^ The application web route-               -> (String -> Application) -- ^ Error handling function-               -> RoutingFunction r-               -> Application-handleWaiError fromUrl toUrl approot handleError handler = \req receiver -> do-  let fUrl = toUrl $ stripOverlapBS approot $ rawPathInfo req-  case fUrl of-    Left err  -> handleError err req receiver-    Right url -> handler (\url params -> (decodeUtf8 approot) `append` (fromUrl url params)) url req receiver
src/Web/Seacat/Server.hs view
@@ -26,11 +26,11 @@ import System.Exit (exitFailure) import System.IO.Error (catchIOError) import Web.Routes.PathInfo (PathInfo)+import Web.Routes.Wai (handleWai)  import Web.Seacat.Configuration (ConfigParser, applyUserConfig, defaults, get', loadConfigFile, reloadConfigFile) import Web.Seacat.Database import Web.Seacat.RequestHandler.Types (Cry(..), MkUrl, Handler, _req, _params, _files)-import Web.Seacat.Router (handleWai)  import qualified Network.Wai.Handler.Warp as W