packages feed

breve 0.3.0.0 → 0.4.0.0

raw patch · 7 files changed

+31/−22 lines, 7 filesdep +warp-tls

Dependencies added: warp-tls

Files

README.md view
@@ -19,7 +19,7 @@ 	     $ breve -The app will start serving on `http://localhost:3000`, listening on every active interface.+The app will start serving on `https://localhost:3000`, listening on every active interface.  ## Configure @@ -33,6 +33,8 @@ hostname = "localhost" port     = 3000 urltable = "$XDG_CONFIG_HOME/breve"+cert     = "/usr/share/tls/breve.crt"+key      = "/usr/share/tls/breve.key" ```  `urltable` is the location of breve url hashtable
breve.cabal view
@@ -1,5 +1,5 @@ name:                breve-version:             0.3.0.0+version:             0.4.0.0 synopsis:            a url shortener description: @@ -29,7 +29,7 @@   other-modules:     Application, Views, Breve.Settings,                      Breve.Generator, Breve.UrlTable   other-extensions:  OverloadedStrings-  build-depends:     base >=4.8 && <5.0, warp,+  build-depends:     base >=4.8 && <5.0, warp, warp-tls,                      Spock, blaze-html, http-types,                      wai, wai-middleware-static, wai-extra,                      transformers, mtl,
src/Breve/Generator.hs view
@@ -31,6 +31,6 @@ intHash :: Url -> Int intHash = decode . fromStrict . hash . pack --- Assing a unique name to the url+-- Assign a unique name to the url nameHash :: Url -> Name nameHash = evalState word . mkStdGen . intHash
src/Breve/Settings.hs view
@@ -6,12 +6,13 @@ import System.Environment.XDG.BaseDir import System.Directory                (doesFileExist) import Data.Configurator-import Data.Monoid+import Network.Wai.Handler.WarpTLS     (tlsSettings, TLSSettings)  data AppSettings = AppSettings   { bindPort     :: Int   , bindUrl      :: String   , urlTable     :: FilePath+  , tlsSetts     :: TLSSettings   }  @@ -27,19 +28,22 @@   configPath <- getUserConfigFile "breve" ""    config <- load [Required configPath] -  host   <- lookupDefault "localhost" config "hostname"-  port   <- lookupDefault 3000        config "port"    -  urls   <- lookupDefault urlsPath    config "urltable"+  host   <- lookupDefault "localhost"                config "hostname"+  port   <- lookupDefault 3000                       config "port"    +  cert   <- lookupDefault "/usr/share/tls/breve.crt" config "cert"+  key    <- lookupDefault "/usr/share/tls/breve.key" config "key"+  urls   <- lookupDefault urlsPath                   config "urltable"    createEmptyIfMissing urls -  let base = "http://" <> host-      url  = if port == 80+  let base = "https://" ++ host+      url  = if port == 443                then base-               else base <> ":" <> show port+               else base ++ ":" ++ show port    return AppSettings     { bindPort = port-    , bindUrl  = url <> "/"+    , bindUrl  = url ++ "/"     , urlTable = urls+    , tlsSetts = tlsSettings cert key     }
src/Main.hs view
@@ -5,18 +5,21 @@ import Breve.UrlTable  import Web.Spock.Safe-import Network.Wai.Handler.Warp (run)--runBreve :: Int -> SpockT IO () -> IO ()-runBreve port app = spockAsApp (spockT id app) >>= run port+import Network.Wai.Handler.WarpTLS (runTLS, TLSSettings)+import Network.Wai.Handler.Warp    (defaultSettings, setPort) +runBreve :: TLSSettings -> Int -> SpockT IO () -> IO ()+runBreve tls port spock =+  spockAsApp (spockT id spock) >>= runTLS tls settings+  where settings = setPort port defaultSettings  main :: IO () main = do   AppSettings { bindUrl               , bindPort-              , urlTable } <- settings+              , urlTable+              , tlsSetts } <- settings   table                    <- load urlTable   putStrLn ("Serving on " ++ bindUrl)-  runBreve bindPort (app bindUrl table)+  runBreve tlsSetts bindPort (app bindUrl table)   
src/Views.hs view
@@ -5,9 +5,9 @@ import Data.Text                     (Text) import Data.Text.Lazy                (toStrict) import Text.Blaze.Html.Renderer.Text (renderHtml)-import Text.Blaze.Html5            as H-import Text.Blaze.Html5.Attributes as A-import qualified Web.Spock.Safe as S+import Text.Blaze.Html5              as H+import Text.Blaze.Html5.Attributes   as A+import qualified Web.Spock.Safe      as S  render :: Html -> S.ActionT IO () render = S.html . toStrict . renderHtml
static/main.css view
@@ -1,4 +1,4 @@-@import url(http://fonts.googleapis.com/css?family=Inconsolata:400,700);+@import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700); @import url(https://cdn.rawgit.com/necolas/normalize.css/master/normalize.css);  body {