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