1
1
mirror of https://github.com/srid/ema.git synced 2024-12-02 09:15:10 +03:00

Server: redirect if server sends static path

This commit is contained in:
Sridhar Ratnakumar 2021-05-22 00:33:23 -04:00
parent 69910d57c9
commit 9326d790de

View File

@ -71,8 +71,9 @@ runServerWithWebSocketHotReload port model render = do
sendRouteHtmlToClient r s = do
case renderWithEmaHtmlShims logger s r of
Left staticPath ->
-- TODO
undefined
-- HACK: Websocket client should check for REDIRECT prefix.
-- Not bothering with JSON to avoid having to JSON parse every HTML dump.
liftIO $ WS.sendTextData conn $ "REDIRECT " <> toText staticPath
Right html ->
liftIO $ WS.sendTextData conn html
log LevelDebug $ " ~~> " <> show r
@ -272,9 +273,13 @@ wsClientShim =
ws.onmessage = evt => {
console.log("ema: ✍ Patching DOM")
setHtml(document.documentElement, evt.data);
// reloadScripts(document.documentElement);
watchCurrentRoute();
if evt.data.startsWith("REDIRECT ") {
document.location.href = evt.data.str.slice("REDIRECT ".length);
} else {
setHtml(document.documentElement, evt.data);
// reloadScripts(document.documentElement);
watchCurrentRoute();
};
};
window.onbeforeunload = evt => { ws.close(); };
window.onpagehide = evt => { ws.close(); };