on master help sign in
Handle error cases better; statically render head in jsaddle mode
commit434afde0bd481cab3892e4b0a87fd9f4f4af8cec authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 16 Jul 2018, 00:37 (8 years ago) parentbf306c0
2 files changed+9−5
lib/backend/src/Obelisk/Backend.hs+5−2 lib/run/src/Obelisk/Run.hs+4−3
lib/backend/src/Obelisk/Backend.hs+5−2
@@ -32,7 +32,7 @@ import Obelisk.Route
3232import Obelisk.Route.Frontend
3333import Reflex.Dom
3434import Snap (MonadSnap, Snap, commandLineConfig, defaultConfig, getsRequest, httpServe, rqPathInfo,
35− rqQueryString, writeBS)
35+ rqQueryString, writeBS, writeText)
3636import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
3737import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
3838
@@ -128,7 +128,10 @@ serveObeliskApp staticAssets frontendApp = \case
128128 ObeliskRoute_Resource resComponent :=> Identity resRest -> case resComponent :=> Identity resRest of
129129 ResourceRoute_Static :=> Identity pathSegments -> serveStaticAssets staticAssets pathSegments
130130 ResourceRoute_Ghcjs :=> Identity pathSegments -> serveGhcjsApp frontendApp $ GhcjsAppRoute_Resource :/ pathSegments
131− ResourceRoute_JSaddleWarp :=> Identity _ -> error "asdf" --TODO
131+ ResourceRoute_JSaddleWarp :=> Identity _ -> do
132+ let msg = "Error: Obelisk.Backend received jsaddle request"
133+ liftIO $ putStrLn $ T.unpack msg
134+ writeText msg
132135
133136serveStaticAssets :: MonadSnap m => StaticAssets -> [Text] -> m ()
134137serveStaticAssets assets pathSegments = serveAsset (_staticAssets_processed assets) (_staticAssets_unprocessed assets) $ T.unpack $ T.intercalate "/" pathSegments
lib/run/src/Obelisk/Run.hs+4−3
@@ -116,12 +116,11 @@ runWidget conf frontend validFullEncoder = do
116116
117117obeliskApp :: forall route backendRoute. ConnectionOptions -> Frontend (R route) -> ValidEncoder (Either Text) (R (Sum backendRoute (ObeliskRoute route))) PageName -> Application -> IO Application
118118obeliskApp opts frontend validFullEncoder backend = do
119− html <- BSLC.fromStrict <$> indexHtml blank --TODO: Something other than `blank` here?
120119 let entryPoint = do
121120 runFrontend validFullEncoder frontend
122121 syncPoint
123122 Right (jsaddleWarpRouteValidEncoder :: ValidEncoder (Either Text) (R JSaddleWarpRoute) PageName) <- return $ checkEncoder jsaddleWarpRouteEncoder
124− jsaddle <- jsaddleWithAppOr opts entryPoint $ error "obeliskApp: jsaddle got a bad URL"
123+ jsaddle <- jsaddleWithAppOr opts entryPoint $ \_ sendResponse -> sendResponse $ W.responseLBS H.status500 [("Content-Type", "text/plain")] "obeliskApp: jsaddle got a bad URL"
125124 return $ \req sendResponse -> case _validEncoder_decode validFullEncoder (W.pathInfo req, mempty) of --TODO: Query strings
126125 Left e -> sendResponse $ W.responseLBS H.status404 [("Content-Type", "text/plain")] $ LBS.fromStrict $ encodeUtf8 e
127126 Right r -> case r of
@@ -130,7 +129,9 @@ obeliskApp opts frontend validFullEncoder backend = do
130129 _ -> flip jsaddle sendResponse $ req
131130 { W.pathInfo = fst $ _validEncoder_encode jsaddleWarpRouteValidEncoder jsaddleRoute
132131 }
133− InR (ObeliskRoute_App _) :=> _ -> sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] html
132+ InR (ObeliskRoute_App appRouteComponent) :=> Identity appRouteRest -> do
133+ html <- fmap BSLC.fromStrict $ indexHtml $ fmap fst $ runEventWriterT $ flip runRoutedT (pure $ appRouteComponent :/ appRouteRest) $ _frontend_head frontend
134+ sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] html
134135 _ -> backend req sendResponse
135136
136137indexHtml :: StaticWidget () () -> IO ByteString