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:
parent
69910d57c9
commit
9326d790de
@ -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(); };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user