Skip to content

Commit

Permalink
Support configuring a custom base url for 'assetPath'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed May 19, 2024
1 parent fa107a6 commit 459e72c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion IHP/Assets/ViewFunctions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import qualified IHP.FrameworkConfig as Config
-- The asset version can be configured using the
-- @IHP_ASSET_VERSION@ environment variable.
assetPath :: (?context :: ControllerContext) => Text -> Text
assetPath assetPath = assetPath <> "?v=" <> assetVersion
assetPath assetPath = baseUrl <> assetPath <> "?v=" <> assetVersion
where
baseUrl = fromMaybe "" ?context.frameworkConfig.assetBaseUrl
{-# INLINABLE assetPath #-}

-- | Returns the assetVersion
Expand Down
4 changes: 4 additions & 0 deletions IHP/FrameworkConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ buildFrameworkConfig appConfig = do
(IdeBaseUrl ideBaseUrl) <- findOption @IdeBaseUrl
(RLSAuthenticatedRole rlsAuthenticatedRole) <- findOption @RLSAuthenticatedRole
(AssetVersion assetVersion) <- findOption @AssetVersion
assetBaseUrl <- envOrNothing "IHP_ASSET_BASEURL"
customMiddleware <- findOption @CustomMiddleware
initializers <- fromMaybe [] <$> findOptionOrNothing @[Initializer]

Expand Down Expand Up @@ -407,6 +408,9 @@ data FrameworkConfig = FrameworkConfig
--
, assetVersion :: !Text

-- | Base URL used by the 'assetPath' helper. Useful to move your static files to a CDN
, assetBaseUrl :: !(Maybe Text)

-- | User provided WAI middleware that is run after IHP's middleware stack.
, customMiddleware :: !CustomMiddleware
, initializers :: ![Initializer]
Expand Down

0 comments on commit 459e72c

Please sign in to comment.