diff --git a/Config/Config.hs b/Config/Config.hs index 7284574..1d9c4d2 100644 --- a/Config/Config.hs +++ b/Config/Config.hs @@ -3,9 +3,13 @@ module Config where import IHP.Prelude import IHP.Environment import IHP.FrameworkConfig +import System.Environment (lookupEnv) + +-- | Feature flag: set IHP_ANNOTATION_LAUNCHER=true to inject the JS launcher. +newtype AnnotationLauncherEnabled = AnnotationLauncherEnabled Bool deriving (Typeable) config :: ConfigBuilder config = do - -- See https://ihp.digitallyinduced.com/Guide/config.html - -- for what you can do here - pure () \ No newline at end of file + launcherEnv <- liftIO (lookupEnv "IHP_ANNOTATION_LAUNCHER") + option (AnnotationLauncherEnabled (launcherEnv == Just "true")) + pure () diff --git a/Web/FrontController.hs b/Web/FrontController.hs index c28dc81..810616a 100644 --- a/Web/FrontController.hs +++ b/Web/FrontController.hs @@ -2,9 +2,11 @@ module Web.FrontController where import IHP.RouterPrelude import IHP.LoginSupport.Middleware +import IHP.ControllerPrelude (getAppConfig) import Generated.Types import Web.Types import Web.Routes () +import Config (AnnotationLauncherEnabled (..)) -- Controllers import Web.Controller.Hubs () @@ -47,6 +49,13 @@ instance InitControllerContext WebApplication where setLayout defaultLayout initAuthentication @User +annotationLauncherScript :: (?context :: ControllerContext) => Html +annotationLauncherScript = + let AnnotationLauncherEnabled enabled = getAppConfig @AnnotationLauncherEnabled + in if enabled + then [hsx||] + else mempty + defaultLayout :: Layout defaultLayout inner = [hsx| @@ -59,6 +68,7 @@ defaultLayout inner = [hsx| + {annotationLauncherScript}