yesod-tls (empty) → 1.4.0
raw patch · 4 files changed
+180/−0 lines, 4 filesdep +basedep +directorydep +fast-loggersetup-changed
Dependencies added: base, directory, fast-logger, monad-logger, safe, template-haskell, unix, wai, wai-extra, warp, warp-tls, yesod
Files
- LICENSE +21/−0
- Setup.hs +2/−0
- Yesod/Default/MainTLS.hs +127/−0
- yesod-tls.cabal +30/−0
+ LICENSE view
@@ -0,0 +1,21 @@+Copyright (c) 2014 Tamás László Fábián++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Yesod/Default/MainTLS.hs view
@@ -0,0 +1,127 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}+module Yesod.Default.MainTLS+ ( defaultMain+ , defaultMainLog+ , defaultRunner+ , defaultDevelApp+ , LogFunc+ ) where++import Yesod.Default.Config+import Network.Wai (Application)+import Network.Wai.Handler.Warp+ (defaultSettings, settingsPort, settingsHost, settingsOnException)+import Network.Wai.Handler.WarpTLS (runTLS, defaultTlsSettings)+import qualified Network.Wai.Handler.Warp as Warp+import System.Directory (doesDirectoryExist, removeDirectoryRecursive)+import Network.Wai.Middleware.Gzip (gzip, GzipFiles (GzipCacheFolder), gzipFiles, def)+import Network.Wai.Middleware.Autohead (autohead)+import Network.Wai.Middleware.Jsonp (jsonp)+import Control.Monad (when)+import System.Environment (getEnvironment)+import Data.Maybe (fromMaybe)+import Safe (readMay)+import Control.Monad.Logger (Loc, LogSource, LogLevel (LevelError), liftLoc)+import System.Log.FastLogger (LogStr, toLogStr)+import Language.Haskell.TH.Syntax (qLocation)++#ifndef WINDOWS+import qualified System.Posix.Signals as Signal+import Control.Concurrent (forkIO, killThread)+import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)+#endif++-- | Run your app, taking environment and port settings from the+-- commandline.+--+-- @'fromArgs'@ helps parse a custom configuration+--+-- > main :: IO ()+-- > main = defaultMain (fromArgs parseExtra) makeApplication+--+defaultMain :: (Show env, Read env)+ => IO (AppConfig env extra)+ -> (AppConfig env extra -> IO Application)+ -> IO ()+defaultMain load getApp = do+ config <- load+ app <- getApp config+ runTLS defaultTlsSettings defaultSettings+ { settingsPort = appPort config+ , settingsHost = appHost config+ } app++type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()++-- | Same as @defaultMain@, but gets a logging function back as well as an+-- @Application@ to install Warp exception handlers.+--+-- Since 1.2.5+defaultMainLog :: (Show env, Read env)+ => IO (AppConfig env extra)+ -> (AppConfig env extra -> IO (Application, LogFunc))+ -> IO ()+defaultMainLog load getApp = do+ config <- load+ (app, logFunc) <- getApp config+ runTLS defaultTlsSettings defaultSettings+ { settingsPort = appPort config+ , settingsHost = appHost config+ , settingsOnException = const $ \e -> when (shouldLog' e) $ logFunc+ $(qLocation >>= liftLoc)+ "yesod"+ LevelError+ (toLogStr $ "Exception from Warp: " ++ show e)+ } app+ where+ shouldLog' = Warp.defaultShouldDisplayException++-- | Run your application continously, listening for SIGINT and exiting+-- when received+--+-- > withYourSite :: AppConfig DefaultEnv -> Logger -> (Application -> IO a) -> IO ()+-- > withYourSite conf logger f = do+-- > Settings.withConnectionPool conf $ \p -> do+-- > runConnectionPool (runMigration yourMigration) p+-- > defaultRunner f $ YourSite conf logger p+defaultRunner :: (Application -> IO ()) -> Application -> IO ()+defaultRunner f app = do+ -- clear the .static-cache so we don't have stale content+ exists <- doesDirectoryExist staticCache+ when exists $ removeDirectoryRecursive staticCache+#ifdef WINDOWS+ f (middlewares app)+#else+ tid <- forkIO $ f (middlewares app) >> return ()+ flag <- newEmptyMVar+ _ <- Signal.installHandler Signal.sigINT (Signal.CatchOnce $ do+ putStrLn "Caught an interrupt"+ killThread tid+ putMVar flag ()) Nothing+ takeMVar flag+#endif+ where+ middlewares = gzip gset . jsonp . autohead++ gset = def { gzipFiles = GzipCacheFolder staticCache }+ staticCache = ".static-cache"++-- | Run your development app using a custom environment type and loader+-- function+defaultDevelApp+ :: (Show env, Read env)+ => IO (AppConfig env extra) -- ^ A means to load your development @'AppConfig'@+ -> (AppConfig env extra -> IO Application) -- ^ Get your @Application@+ -> IO (Int, Application)+defaultDevelApp load getApp = do+ conf <- load+ env <- getEnvironment+ let p = fromMaybe (appPort conf) $ lookup "PORT" env >>= readMay+ pdisplay = fromMaybe p $ lookup "DISPLAY_PORT" env >>= readMay+ putStrLn $ "Devel application launched: http://localhost:" ++ show pdisplay+ app <- getApp conf+ return (p, app)+
+ yesod-tls.cabal view
@@ -0,0 +1,30 @@+name: yesod-tls+version: 1.4.0+synopsis: Provides main functions using warp-tls for yesod projects+description: This package makes possible to build Yesod web applications that provide SSL support.+homepage: http://github.com/netom/yesod-tls+license: MIT+license-file: LICENSE+author: Tamás László Fábián <giganetom@gmail.com>+maintainer: Tamás László Fábián <giganetom@gmail.com>+category: Web, Yesod+build-type: Simple+cabal-version: >=1.6++library+ build-depends: base >=4.3 && < 5+ , yesod >= 1.4.0 && < 1.5+ , wai >= 1.3+ , wai-extra >= 1.3+ , warp >= 1.3+ , warp-tls >= 3.0+ , template-haskell+ , monad-logger+ , fast-logger+ , safe+ , directory++ if !os(windows)+ build-depends: unix++ exposed-modules: Yesod.Default.MainTLS