Last active
October 29, 2018 09:49
-
-
Save 3noch/ee335c94b92ea01b7fee9e6291e833be to your computer and use it in GitHub Desktop.
Reflex-DOM Auto Reload Development with ghcid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:set prompt "> " | |
:set -isrc | |
:load Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
port=${1:-9090} | |
ghcid -W --test "devMainAutoReload apiServer appWidget $port" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Language.Javascript.JSaddle (JSM) | |
import Language.Javascript.JSaddle.Run (syncPoint) | |
import Language.Javascript.JSaddle.WebSockets (debugWrapper, jsaddleWithAppOr) | |
import Network.Wai (Application) | |
import Network.Wai.Handler.Warp (defaultSettings, run, runSettings, setPort, setTimeout) | |
import Network.WebSockets (defaultConnectionOptions) | |
-- | A @main@ for doing development. | |
devMain :: Application -> JSM () -> Int -> IO () | |
devMain backend frontend port = do | |
putStrLn $ "Running dev server on localhost:" <> show port | |
app <- jsaddleWithAppOr | |
defaultConnectionOptions | |
(frontend >> syncPoint) | |
backend | |
runSettings (defaultSettings & setTimeout 3600 & setPort port) app | |
-- | A version of @devMain@ that can be used with @ghcid --test@ to get an auto-reloading server. | |
devMainAutoReload :: Application -> JSM () -> Int -> IO () | |
devMainAutoReload backend frontend port = | |
debugWrapper $ \refreshMiddleware registerContext -> | |
devMain (refreshMiddleware backend) (registerContext >> frontend) port |
Tip: Have your backend Application
serve any static files needed by the front-end.
Thanks! I have implemented this here: https://github.com/rvl/flatris
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://gist.github.com/dalaing/73b24b9faea0f51c8e4cbc6d1311516e