on master help sign in
Handle error cases better; statically render head in jsaddle mode
434afdeRyan Trinkle
lib/backend/src/Obelisk/Backend.hs+5−2
@@ -32,7 +32,7 @@ import Obelisk.Route
32import Obelisk.Route.Frontend
32import Obelisk.Route.Frontend
33import Reflex.Dom
33import Reflex.Dom
34import Snap (MonadSnap, Snap, commandLineConfig, defaultConfig, getsRequest, httpServe, rqPathInfo,
34import Snap (MonadSnap, Snap, commandLineConfig, defaultConfig, getsRequest, httpServe, rqPathInfo,
35− rqQueryString, writeBS)
35+ rqQueryString, writeBS, writeText)
36import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
36import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
37import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
37import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
38
38
@@ -128,7 +128,10 @@ serveObeliskApp staticAssets frontendApp = \case
128 ObeliskRoute_Resource resComponent :=> Identity resRest -> case resComponent :=> Identity resRest of
128 ObeliskRoute_Resource resComponent :=> Identity resRest -> case resComponent :=> Identity resRest of
129 ResourceRoute_Static :=> Identity pathSegments -> serveStaticAssets staticAssets pathSegments
129 ResourceRoute_Static :=> Identity pathSegments -> serveStaticAssets staticAssets pathSegments
130 ResourceRoute_Ghcjs :=> Identity pathSegments -> serveGhcjsApp frontendApp $ GhcjsAppRoute_Resource :/ pathSegments
130 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
132
135
133serveStaticAssets :: MonadSnap m => StaticAssets -> [Text] -> m ()
136serveStaticAssets :: MonadSnap m => StaticAssets -> [Text] -> m ()
134serveStaticAssets assets pathSegments = serveAsset (_staticAssets_processed assets) (_staticAssets_unprocessed assets) $ T.unpack $ T.intercalate "/" pathSegments
137serveStaticAssets 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
116
116
117obeliskApp :: forall route backendRoute. ConnectionOptions -> Frontend (R route) -> ValidEncoder (Either Text) (R (Sum backendRoute (ObeliskRoute route))) PageName -> Application -> IO Application
117obeliskApp :: forall route backendRoute. ConnectionOptions -> Frontend (R route) -> ValidEncoder (Either Text) (R (Sum backendRoute (ObeliskRoute route))) PageName -> Application -> IO Application
118obeliskApp opts frontend validFullEncoder backend = do
118obeliskApp opts frontend validFullEncoder backend = do
119− html <- BSLC.fromStrict <$> indexHtml blank --TODO: Something other than `blank` here?
120 let entryPoint = do
119 let entryPoint = do
121 runFrontend validFullEncoder frontend
120 runFrontend validFullEncoder frontend
122 syncPoint
121 syncPoint
123 Right (jsaddleWarpRouteValidEncoder :: ValidEncoder (Either Text) (R JSaddleWarpRoute) PageName) <- return $ checkEncoder jsaddleWarpRouteEncoder
122 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"
125 return $ \req sendResponse -> case _validEncoder_decode validFullEncoder (W.pathInfo req, mempty) of --TODO: Query strings
124 return $ \req sendResponse -> case _validEncoder_decode validFullEncoder (W.pathInfo req, mempty) of --TODO: Query strings
126 Left e -> sendResponse $ W.responseLBS H.status404 [("Content-Type", "text/plain")] $ LBS.fromStrict $ encodeUtf8 e
125 Left e -> sendResponse $ W.responseLBS H.status404 [("Content-Type", "text/plain")] $ LBS.fromStrict $ encodeUtf8 e
127 Right r -> case r of
126 Right r -> case r of
@@ -130,7 +129,9 @@ obeliskApp opts frontend validFullEncoder backend = do
130 _ -> flip jsaddle sendResponse $ req
129 _ -> flip jsaddle sendResponse $ req
131 { W.pathInfo = fst $ _validEncoder_encode jsaddleWarpRouteValidEncoder jsaddleRoute
130 { W.pathInfo = fst $ _validEncoder_encode jsaddleWarpRouteValidEncoder jsaddleRoute
132 }
131 }
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
133− InR (ObeliskRoute_App _) :=> _ -> sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] html
134+ sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] html
134 _ -> backend req sendResponse
135 _ -> backend req sendResponse
135
136
136indexHtml :: StaticWidget () () -> IO ByteString
137indexHtml :: StaticWidget () () -> IO ByteString