leo
9ab2d0ae0b
* add log messages telling the user what went wrong if the app fails to start * improve existing log messages * cleanup: close channels when exiting * cleanup: stop listening for signals when exiting
96 lines
2.4 KiB
Haskell
96 lines
2.4 KiB
Haskell
-- convenience funcs for validation.
|
|
let Prelude =
|
|
https://prelude.dhall-lang.org/v20.2.0/package.dhall
|
|
sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b
|
|
|
|
let NuConfig =
|
|
-- | define a configuration schema.
|
|
{ Type =
|
|
{ Port : Natural
|
|
, AppName : Text
|
|
, LiveMode : Bool
|
|
, DevelMode : Bool
|
|
, LoginCookieName : Optional Text
|
|
}
|
|
, default =
|
|
{ Port = 3000
|
|
, AppName = "pcmt"
|
|
, LiveMode = False
|
|
, DevelMode = False
|
|
, LoginCookieName = None Text
|
|
}
|
|
}
|
|
|
|
let NuConfig/validate
|
|
: NuConfig.Type -> Type
|
|
=
|
|
-- | define validation.
|
|
\(c : NuConfig.Type) ->
|
|
let expected = { validPort = True }
|
|
|
|
let actual =
|
|
{ validPort =
|
|
-- | make sure port number belongs to the <1;65565> range.
|
|
Prelude.Natural.lessThanEqual 1 c.Port
|
|
&& Prelude.Natural.lessThanEqual c.Port 65565
|
|
}
|
|
|
|
in expected === actual
|
|
|
|
let nuconf = NuConfig::{ LiveMode = True, DevelMode = True }
|
|
|
|
let _ =
|
|
-- | validate the configuration.
|
|
assert : NuConfig/validate nuconf
|
|
|
|
let Config =
|
|
-- | define configuration schema.
|
|
{ Host : Text
|
|
, Port : Natural
|
|
, AppName : Text
|
|
, LiveMode : Bool
|
|
, DevelMode : Bool
|
|
, SessionCookieName : Text
|
|
, SessionCookieSecret : Text
|
|
}
|
|
|
|
let defconf
|
|
-- | a full default configuration.
|
|
-- | TODO: have this reside on the Internet and import it similar to how
|
|
-- | the Dhall Prelude is imported.
|
|
: Config
|
|
= { Host = ""
|
|
, Port = 3000
|
|
, AppName = "pcmt"
|
|
, LiveMode = False
|
|
, DevelMode = False
|
|
, SessionCookieName = "sessionz"
|
|
, SessionCookieSecret = "secret"
|
|
}
|
|
|
|
let conf
|
|
: Config
|
|
= defconf // { LiveMode = True, DevelMode = False }
|
|
|
|
let Config/validate
|
|
: Config -> Type
|
|
=
|
|
-- | define validation.
|
|
\(config : Config) ->
|
|
let expected = { validPort = True }
|
|
|
|
let actual =
|
|
{ validPort =
|
|
-- | make sure port number belongs to the <1;65565> range.
|
|
Prelude.Natural.lessThanEqual 1 config.Port
|
|
&& Prelude.Natural.lessThanEqual config.Port 65565
|
|
}
|
|
|
|
in expected === actual
|
|
|
|
let _ =
|
|
-- | validate the configuration.
|
|
assert : Config/validate conf
|
|
|
|
in conf
|