web: modify the default base url when a custom port is specified
This commit is contained in:
parent
3e3475bd76
commit
85b2307e78
@ -5,7 +5,6 @@
|
|||||||
module Hledger.Web.Options
|
module Hledger.Web.Options
|
||||||
where
|
where
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Text (unpack)
|
|
||||||
import System.Console.CmdArgs
|
import System.Console.CmdArgs
|
||||||
import System.Console.CmdArgs.Explicit
|
import System.Console.CmdArgs.Explicit
|
||||||
|
|
||||||
@ -17,8 +16,7 @@ import Hledger.Web.Settings
|
|||||||
progname = Hledger.Cli.progname ++ "-web"
|
progname = Hledger.Cli.progname ++ "-web"
|
||||||
progversion = progversionstr progname
|
progversion = progversionstr progname
|
||||||
|
|
||||||
defbaseurl = unpack defapproot
|
defbaseurl' = (reverse $ drop 4 $ reverse $ defbaseurl defport) ++ "PORT"
|
||||||
defbaseurl' = (reverse $ drop 4 $ reverse defbaseurl) ++ "PORT"
|
|
||||||
|
|
||||||
webflags = [
|
webflags = [
|
||||||
flagReq ["base-url"] (\s opts -> Right $ setopt "base-url" s opts) "URL" ("set the base url (default: "++defbaseurl'++")")
|
flagReq ["base-url"] (\s opts -> Right $ setopt "base-url" s opts) "URL" ("set the base url (default: "++defbaseurl'++")")
|
||||||
@ -55,9 +53,10 @@ defwebopts = WebOpts
|
|||||||
toWebOpts :: RawOpts -> IO WebOpts
|
toWebOpts :: RawOpts -> IO WebOpts
|
||||||
toWebOpts rawopts = do
|
toWebOpts rawopts = do
|
||||||
cliopts <- toCliOpts rawopts
|
cliopts <- toCliOpts rawopts
|
||||||
|
let p = fromMaybe defport $ maybeintopt "port" rawopts
|
||||||
return defwebopts {
|
return defwebopts {
|
||||||
base_url_ = fromMaybe defbaseurl $ maybestringopt "base-url" rawopts
|
port_ = p
|
||||||
,port_ = fromMaybe defport $ maybeintopt "port" rawopts
|
,base_url_ = fromMaybe (defbaseurl p) $ maybestringopt "base-url" rawopts
|
||||||
,cliopts_ = cliopts
|
,cliopts_ = cliopts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,8 @@ module Hledger.Web.Settings
|
|||||||
, AppEnvironment(..)
|
, AppEnvironment(..)
|
||||||
, AppConfig(..)
|
, AppConfig(..)
|
||||||
|
|
||||||
, defhost
|
|
||||||
, defport
|
, defport
|
||||||
, defapproot
|
, defbaseurl
|
||||||
, hledgerorgurl
|
, hledgerorgurl
|
||||||
, manualurl
|
, manualurl
|
||||||
, datadir
|
, datadir
|
||||||
@ -51,11 +50,8 @@ manualurl = hledgerorgurl++"/MANUAL.html"
|
|||||||
defport :: Int
|
defport :: Int
|
||||||
defport = 5000
|
defport = 5000
|
||||||
|
|
||||||
defhost :: String
|
defbaseurl :: Int -> String
|
||||||
defhost = "localhost"
|
defbaseurl port = printf "http://localhost:%d" port
|
||||||
|
|
||||||
defapproot :: Text
|
|
||||||
defapproot = pack $ printf "http://%s:%d" defhost defport
|
|
||||||
|
|
||||||
|
|
||||||
data AppEnvironment = Test
|
data AppEnvironment = Test
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user