breve 0.4.3.1 → 0.4.4.0
raw patch · 4 files changed
+35/−27 lines, 4 files
Files
- README.md +4/−2
- breve.cabal +1/−1
- src/Breve/Settings.hs +26/−23
- src/Main.hs +4/−1
README.md view
@@ -4,7 +4,7 @@ Breve is a web application that provides a simple interface to shortening long urls creating links smaller and easier to remember. -You can find a running instance on [breve.xyz](https://breve.xyz)+You can find a running instance on [brve.bit](https://brve.bit) It creates links in the form of "/emeaoinqua": easier to remember than alphanumeric strings like "/1Cqw8lHw" used by several services.@@ -27,13 +27,15 @@ You can change the options by editing the config file. When you start the app an empty one will be created in:-`$XDG_CONFIG_HOME/breve` or `~/.config/breve` if unset.+`$XDG_CONFIG_HOME/breve`, `~/.config/breve` if unset,+or you can pass a path as the first argument of breve. The default values are: ```ini hostname = "localhost" port = 3000+baseurl = "https://localhost:3000/" urltable = "$XDG_CONFIG_HOME/breve" tls { cert = "/usr/share/tls/breve.crt"
breve.cabal view
@@ -1,5 +1,5 @@ name: breve-version: 0.4.3.1+version: 0.4.4.0 synopsis: a url shortener description:
src/Breve/Settings.hs view
@@ -29,34 +29,37 @@ when (not exists) (writeFile file "") -settings :: IO AppSettings-settings = do- urlsPath <- getUserDataFile "breve" ""- configPath <- getUserConfigFile "breve" ""+settings :: Maybe FilePath -> IO AppSettings+settings path = do+ configPath <- case path of+ Just path -> return path+ Nothing -> getUserConfigFile "breve" "" - config <- load [Required configPath]- host <- lookupDefault "localhost" config "hostname"- port <- lookupDefault 3000 config "port" - urls <- lookupDefault urlsPath config "urltable"- cert <- lookupDefault "/usr/share/tls/breve.crt" config "tls.cert"- key <- lookupDefault "/usr/share/tls/breve.key" config "tls.key"- chain <- lookupDefault [] config "tls.chain"+ urlsPath <- getUserDataFile "breve" "" - createEmptyIfMissing urls+ config <- load [Required configPath]+ host <- lookupDefault "localhost" config "hostname"+ portnum <- lookupDefault 3000 config "port"+ urls <- lookupDefault urlsPath config "urltable"+ cert <- lookupDefault "/usr/share/tls/breve.crt" config "tls.cert"+ key <- lookupDefault "/usr/share/tls/breve.key" config "tls.key"+ chain <- lookupDefault [] config "tls.chain" - let base = "https://" <> host- url = if port == 443- then base- else base <> ":" <> pack (show port)- tls = (tlsSettingsChain cert chain key)- { tlsAllowedVersions = [TLS12, TLS11]- , tlsCiphers = ciphersuite_strong- }+ let+ port = if portnum == 443 then "" else ":" <> pack (show portnum)+ url = "https://" <> host <> port <> "/" + baseURL <- lookupDefault url config "baseurl"++ createEmptyIfMissing urls+ return AppSettings { bindHost = host- , bindPort = port- , bindUrl = url <> "/"+ , bindPort = portnum+ , bindUrl = baseURL , urlTable = urls- , tlsSettings = tls+ , tlsSettings = (tlsSettingsChain cert chain key)+ { tlsAllowedVersions = [TLS12, TLS11]+ , tlsCiphers = ciphersuite_strong+ } }
src/Main.hs view
@@ -5,8 +5,10 @@ import Breve.UrlTable import Data.Text (Text, unpack)+import Data.Maybe (listToMaybe) import Control.Concurrent (forkIO) import Control.Monad+import System.Environment (getArgs) import Web.Spock.Core import Network.Wai.Handler.WarpTLS (runTLS, TLSSettings)@@ -28,7 +30,8 @@ main :: IO () main = do- AppSettings {..} <- settings+ configPath <- fmap listToMaybe getArgs+ AppSettings {..} <- settings configPath table <- load urlTable when (bindPort == 443) (forkIO' $ runTLSRedirect bindHost)