mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-29 00:54:52 +09:00
Load settings only at run time, not using compile time settings at all
This commit is contained in:
parent
4b20ed23b6
commit
057f57ff0d
4 changed files with 38 additions and 24 deletions
|
@ -120,7 +120,7 @@ makeFoundation appSettings = do
|
|||
appLogger <- newStdoutLoggerSet defaultBufSize >>= makeYesodLogger
|
||||
appStatic <-
|
||||
(if appMutableStatic appSettings then staticDevel else static)
|
||||
(appStaticDir appSettings)
|
||||
appStaticDir
|
||||
|
||||
appMailQueue <-
|
||||
case appMail appSettings of
|
||||
|
@ -286,7 +286,8 @@ appMain = do
|
|||
settings <- loadYamlSettingsArgs
|
||||
-- Fall back to compile-time values, set to [] to require values at
|
||||
-- runtime
|
||||
[configSettingsYmlValue]
|
||||
--[configSettingsYmlValue]
|
||||
[]
|
||||
|
||||
-- Allow environment variables to override
|
||||
useEnv
|
||||
|
|
|
@ -486,11 +486,10 @@ instance Yesod App where
|
|||
-- users receiving stale content.
|
||||
addStaticContent ext mime content = do
|
||||
master <- getYesod
|
||||
let staticDir = appStaticDir $ appSettings master
|
||||
addStaticContentExternal
|
||||
discardm
|
||||
genFileName
|
||||
staticDir
|
||||
appStaticDir
|
||||
(StaticR . flip StaticRoute [])
|
||||
ext
|
||||
mime
|
||||
|
|
|
@ -50,14 +50,34 @@ import qualified Data.Text as T
|
|||
|
||||
import Yesod.Mail.Send (MailSettings)
|
||||
|
||||
developmentMode :: Bool
|
||||
developmentMode =
|
||||
#if DEVELOPMENT
|
||||
True
|
||||
#else
|
||||
False
|
||||
#endif
|
||||
|
||||
-- | Directory from which to serve static files.
|
||||
appStaticDir :: String
|
||||
appStaticDir = "static"
|
||||
|
||||
-- | Use the reload version of templates
|
||||
appReloadTemplates :: Bool
|
||||
appReloadTemplates = developmentMode
|
||||
|
||||
-- | Perform no stylesheet/script combining
|
||||
appSkipCombining :: Bool
|
||||
appSkipCombining = developmentMode
|
||||
|
||||
-- | Runtime settings to configure this application. These settings can be
|
||||
-- loaded from various sources: defaults, environment variables, config files,
|
||||
-- theoretically even a database.
|
||||
data AppSettings = AppSettings
|
||||
{ -- | Directory from which to serve static files.
|
||||
appStaticDir :: String
|
||||
--appStaticDir :: String
|
||||
-- | Configuration settings for accessing the database.
|
||||
, appDatabaseConf :: PostgresConf
|
||||
appDatabaseConf :: PostgresConf
|
||||
-- | Maximal number of remote instance-scope keys to cache in our local
|
||||
-- database per instance.
|
||||
, appMaxInstanceKeys :: Maybe Int
|
||||
|
@ -93,11 +113,11 @@ data AppSettings = AppSettings
|
|||
-- | Should all log messages be displayed?
|
||||
, appShouldLogAll :: Bool
|
||||
-- | Use the reload version of templates
|
||||
, appReloadTemplates :: Bool
|
||||
--, appReloadTemplates :: Bool
|
||||
-- | Assume that files in the static dir may change after compilation
|
||||
, appMutableStatic :: Bool
|
||||
-- | Perform no stylesheet/script combining
|
||||
, appSkipCombining :: Bool
|
||||
--, appSkipCombining :: Bool
|
||||
|
||||
-- | Load SVG font file from the data file path of the @SVGFonts@
|
||||
-- library, instead of the app's production runtime data directory.
|
||||
|
@ -166,18 +186,10 @@ data AppSettings = AppSettings
|
|||
, appHighlightStyle :: Text
|
||||
}
|
||||
|
||||
developmentMode :: Bool
|
||||
developmentMode =
|
||||
#if DEVELOPMENT
|
||||
True
|
||||
#else
|
||||
False
|
||||
#endif
|
||||
|
||||
instance FromJSON AppSettings where
|
||||
parseJSON = withObject "AppSettings" $ \ o -> do
|
||||
let defaultDev = developmentMode
|
||||
appStaticDir <- o .: "static-dir"
|
||||
--appStaticDir <- o .: "static-dir"
|
||||
appDatabaseConf <- o .: "database"
|
||||
appMaxInstanceKeys <- o .:? "max-instance-keys"
|
||||
appMaxActorKeys <- o .:? "max-actor-keys"
|
||||
|
@ -194,9 +206,9 @@ instance FromJSON AppSettings where
|
|||
|
||||
appDetailedRequestLogging <- o .:? "detailed-logging" .!= defaultDev
|
||||
appShouldLogAll <- o .:? "should-log-all" .!= defaultDev
|
||||
appReloadTemplates <- o .:? "reload-templates" .!= defaultDev
|
||||
--appReloadTemplates <- o .:? "reload-templates" .!= defaultDev
|
||||
appMutableStatic <- o .:? "mutable-static" .!= defaultDev
|
||||
appSkipCombining <- o .:? "skip-combining" .!= defaultDev
|
||||
--appSkipCombining <- o .:? "skip-combining" .!= defaultDev
|
||||
|
||||
appLoadFontFromLibData <- o .:? "load-font-from-lib-data" .!= defaultDev
|
||||
|
||||
|
@ -249,11 +261,12 @@ combineSettings = def
|
|||
widgetFile :: String -> Q Exp
|
||||
widgetFile =
|
||||
let wf =
|
||||
if appReloadTemplates compileTimeAppSettings
|
||||
if appReloadTemplates
|
||||
then widgetFileReload
|
||||
else widgetFileNoReload
|
||||
in wf widgetFileSettings
|
||||
|
||||
{-
|
||||
-- | Raw bytes at compile time of @config/settings.yml@
|
||||
configSettingsYmlBS :: ByteString
|
||||
configSettingsYmlBS = $(embedFile configSettingsYml)
|
||||
|
@ -269,6 +282,7 @@ compileTimeAppSettings =
|
|||
case fromJSON $ applyEnvValue False mempty configSettingsYmlValue of
|
||||
Error e -> error e
|
||||
Success settings -> settings
|
||||
-}
|
||||
|
||||
-- The following two functions can be used to combine multiple CSS or JS files
|
||||
-- at compile time to decrease the number of http requests.
|
||||
|
@ -279,11 +293,11 @@ compileTimeAppSettings =
|
|||
combineStylesheets :: Name -> [Route Static] -> Q Exp
|
||||
combineStylesheets =
|
||||
combineStylesheets'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
appSkipCombining
|
||||
combineSettings
|
||||
|
||||
combineScripts :: Name -> [Route Static] -> Q Exp
|
||||
combineScripts =
|
||||
combineScripts'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
appSkipCombining
|
||||
combineSettings
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
module Vervis.Settings.StaticFiles where
|
||||
|
||||
import Vervis.Settings (appStaticDir, compileTimeAppSettings)
|
||||
import Vervis.Settings (appStaticDir)
|
||||
import Yesod.Static (staticFiles)
|
||||
|
||||
-- This generates easy references to files in the static directory at compile time,
|
||||
|
@ -30,4 +30,4 @@ import Yesod.Static (staticFiles)
|
|||
-- If the identifier is not available, you may use:
|
||||
--
|
||||
-- StaticFile ["js", "script.js"] []
|
||||
staticFiles (appStaticDir compileTimeAppSettings)
|
||||
staticFiles appStaticDir
|
||||
|
|
Loading…
Reference in a new issue