2014-03-07 21:43:27 +00:00
|
|
|
-- | Devel web server.
|
|
|
|
|
|
|
|
module DevelMain where
|
|
|
|
|
|
|
|
import HL.Dispatch ()
|
2014-03-14 18:04:25 +00:00
|
|
|
import HL.Foundation
|
2014-03-07 21:43:27 +00:00
|
|
|
|
|
|
|
import Control.Concurrent
|
|
|
|
import Data.IORef
|
|
|
|
import Foreign.Store
|
|
|
|
import Network.Wai.Handler.Warp
|
2014-03-14 18:04:25 +00:00
|
|
|
import Yesod
|
2014-03-07 21:43:27 +00:00
|
|
|
import Yesod.Static
|
|
|
|
|
|
|
|
-- | Start the web server.
|
|
|
|
main :: IO (Store (IORef Application))
|
|
|
|
main =
|
|
|
|
do s <- static "static"
|
2014-03-07 22:37:04 +00:00
|
|
|
c <- newChan
|
|
|
|
app <- toWaiApp (App s c)
|
2014-03-07 21:43:27 +00:00
|
|
|
ref <- newIORef app
|
|
|
|
tid <- forkIO
|
|
|
|
(runSettings
|
2014-05-28 05:03:30 +00:00
|
|
|
(setPort 1990 defaultSettings)
|
2014-03-07 22:37:04 +00:00
|
|
|
(\req ->
|
|
|
|
do handler <- readIORef ref
|
|
|
|
handler req))
|
2014-03-07 21:43:27 +00:00
|
|
|
_ <- newStore tid
|
2014-03-14 18:04:25 +00:00
|
|
|
ref' <- newStore ref
|
|
|
|
_ <- newStore c
|
|
|
|
return ref'
|
2014-03-07 21:43:27 +00:00
|
|
|
|
|
|
|
-- | 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
|
2014-03-07 22:37:04 +00:00
|
|
|
c <- readStore (Store 2)
|
|
|
|
writeChan c ()
|
2014-03-07 21:43:27 +00:00
|
|
|
s <- static "static"
|
2014-03-07 22:37:04 +00:00
|
|
|
app <- toWaiApp (App s c)
|
2014-03-07 21:43:27 +00:00
|
|
|
writeIORef ref app
|
|
|
|
return store
|