on master help sign in
Set charset when statically rendering
commitd90a40d14f0d3b39d879f42fe7ed15472738fd28 authorAli Abrar <aliabrar@gmail.com> dateMon 29 Oct 2018, 12:47 (8 years ago) parentcaf49a2
2 files changed+9−4
lib/backend/src/Obelisk/Backend.hs+8−3 lib/run/src/Obelisk/Run.hs+1−1
lib/backend/src/Obelisk/Backend.hs+8−3
@@ -16,6 +16,7 @@ module Obelisk.Backend
1616 , serveDefaultObeliskApp
1717 , prettifyOutput
1818 , runBackend
19+ , staticRenderContentType
1920 ) where
2021
2122import Prelude hiding (id, (.))
@@ -38,8 +39,8 @@ import Obelisk.ExecutableConfig.Inject (injectExecutableConfigs)
3839import Obelisk.Frontend
3940import Obelisk.Route
4041import Reflex.Dom
41−import Snap (MonadSnap, Snap, commandLineConfig, defaultConfig, getsRequest, httpServe, rqPathInfo,
42− rqQueryString, writeBS, writeText)
42+import Snap (MonadSnap, Snap, commandLineConfig, defaultConfig, getsRequest, httpServe, modifyResponse
43+ , rqPathInfo, rqQueryString, setContentType, writeBS, writeText)
4344import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
4445import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
4546
@@ -132,10 +133,14 @@ data GhcjsAppRoute :: (* -> *) -> * -> * where
132133 GhcjsAppRoute_App :: appRouteComponent a -> GhcjsAppRoute appRouteComponent a
133134 GhcjsAppRoute_Resource :: GhcjsAppRoute appRouteComponent [Text]
134135
136+staticRenderContentType :: ByteString
137+staticRenderContentType = "text/html; charset=utf-8"
138+
135139--TODO: Don't assume we're being served at "/"
136140serveGhcjsApp :: MonadSnap m => GhcjsApp (R appRouteComponent) -> R (GhcjsAppRoute appRouteComponent) -> m ()
137141serveGhcjsApp app = \case
138− GhcjsAppRoute_App appRouteComponent :=> Identity appRouteRest ->
142+ GhcjsAppRoute_App appRouteComponent :=> Identity appRouteRest -> do
143+ modifyResponse $ setContentType staticRenderContentType
139144 writeBS <=< liftIO $ renderGhcjsFrontend (appRouteComponent :/ appRouteRest) $ _ghcjsApp_value app
140145 GhcjsAppRoute_Resource :=> Identity pathSegments -> serveStaticAssets (_ghcjsApp_compiled app) pathSegments
141146
lib/run/src/Obelisk/Run.hs+1−1
@@ -143,7 +143,7 @@ obeliskApp opts frontend validFullEncoder uri backend = do
143143 }
144144 InR (ObeliskRoute_App appRouteComponent) :=> Identity appRouteRest -> do
145145 html <- renderJsaddleFrontend (appRouteComponent :/ appRouteRest) frontend
146− sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] $ BSLC.fromStrict html
146+ sendResponse $ W.responseLBS H.status200 [("Content-Type", staticRenderContentType)] $ BSLC.fromStrict html
147147 _ -> backend req sendResponse
148148
149149renderJsaddleFrontend :: route -> Frontend route -> IO ByteString