From 141b98d3ccb34df3cf71076979aca9708e54323e Mon Sep 17 00:00:00 2001 From: Chris Done Date: Fri, 30 May 2014 14:59:48 +0200 Subject: [PATCH] Add a DevelMain file for use in GHCi --- .dir-locals.el | 3 ++- DevelMain.hs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 DevelMain.hs diff --git a/.dir-locals.el b/.dir-locals.el index b746084..0fd6eb4 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,2 +1,3 @@ ((haskell-mode . ((haskell-process-type . cabal-repl) - (haskell-indent-spaces . 4)))) + (haskell-indent-spaces . 4) + (haskell-process-use-ghci . t)))) diff --git a/DevelMain.hs b/DevelMain.hs new file mode 100644 index 0000000..ede813a --- /dev/null +++ b/DevelMain.hs @@ -0,0 +1,52 @@ +{-# LANGUAGE ImplicitPrelude #-} + +-- | Devel web server. +-- +-- > :l DevelMain +-- > DevelMain.update +-- +-- To start/restart the server. + +module DevelMain where + +import Application (getApplicationDev) + +import Control.Concurrent +import Data.IORef +import Foreign.Store +import Network.Wai.Handler.Warp +import Yesod +import Yesod.Static + +-- | Start the web server. +main :: IO (Store (IORef Application)) +main = + do s <- static "static" + c <- newChan + (port,app) <- getApplicationDev + ref <- newIORef app + tid <- forkIO + (runSettings + (setPort port defaultSettings) + (\req -> + do handler <- readIORef ref + handler req)) + _ <- newStore tid + ref' <- newStore ref + _ <- newStore c + return ref' + +-- | Update the server, start it if not running. +update :: IO (Store (IORef Application)) +update = + do m <- lookupStore 1 + case m of + Nothing -> main + Just store -> + do ref <- readStore store + c <- readStore (Store 2) + writeChan c () + s <- static "static" + (port,app) <- getApplicationDev + writeIORef ref app + return store