mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-02-05 15:50:26 +01:00
Add a DevelMain file for use in GHCi
This commit is contained in:
parent
8cb0212f8b
commit
141b98d3cc
@ -1,2 +1,3 @@
|
|||||||
((haskell-mode . ((haskell-process-type . cabal-repl)
|
((haskell-mode . ((haskell-process-type . cabal-repl)
|
||||||
(haskell-indent-spaces . 4))))
|
(haskell-indent-spaces . 4)
|
||||||
|
(haskell-process-use-ghci . t))))
|
||||||
|
|||||||
52
DevelMain.hs
Normal file
52
DevelMain.hs
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user