Skip to content

Commit

Permalink
Pass Sqlite3 connection to controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Mar 20, 2013
1 parent c4774c8 commit a372318
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Application.hs
Expand Up @@ -34,7 +34,7 @@ responseTextBuilder s h = ResponseBuilder s h . Blaze.fromLazyText . TL.toLazyTe
on404 :: Application on404 :: Application
on404 _ = string notFound404 [] "Not Found" on404 _ = string notFound404 [] "Not Found"


reportFor :: RippleAddress -> Application reportFor :: Connection -> RippleAddress -> Application
reportFor adr req = return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr) reportFor db adr req = return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr)
where where
Just headers = stringHeaders [("Content-Type", "text/html; charset=utf8")] Just headers = stringHeaders [("Content-Type", "text/html; charset=utf8")]
11 changes: 7 additions & 4 deletions Main.hs
@@ -1,18 +1,21 @@
module Main (main) where module Main (main) where


import Control.Monad (void)

import Network.Wai.Handler.Warp (run) import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.RequestLogger (logStdoutDev) import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Middleware.Autohead (autohead) import Network.Wai.Middleware.Autohead (autohead)
import Network.Wai.Middleware.Jsonp (jsonp) import Network.Wai.Middleware.Jsonp (jsonp)
import Network.Wai.Middleware.AcceptOverride (acceptOverride) import Network.Wai.Middleware.AcceptOverride (acceptOverride)


import Database.SQLite.Simple (withConnection)

import Network.Wai.Dispatch import Network.Wai.Dispatch
import Routes import Routes
import Application import Application


main :: IO () main :: IO ()
main = do main = void $ withConnection "./dev.db"
putStrLn "Running..." (\db -> run 3000 $
run 3000 $
logStdoutDev $ autohead $ acceptOverride $ jsonp $ -- Middleware logStdoutDev $ autohead $ acceptOverride $ jsonp $ -- Middleware
dispatch on404 $ routes -- Do routing dispatch on404 $ routes db) -- Do routing
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -2,10 +2,10 @@ Main: Main.hs Application.hs Routes.hs MustacheTemplates.hs
ghc -Wall -fno-warn-name-shadowing Main.hs ghc -Wall -fno-warn-name-shadowing Main.hs


Routes.hs: routes Routes.hs: routes
routeGenerator -r -m Application -n 0 $< > $@ routeGenerator -r -m Application -n 1 $< > $@


PathHelpers.hs: routes PathHelpers.hs: routes
routeGenerator -p -n 0 $< > $@ routeGenerator -p -n 1 $< > $@


MustacheTemplates.hs: Records.hs view/report.mustache MustacheTemplates.hs: Records.hs view/report.mustache
mustache2hs -m Records.hs view/report.mustache Report > $@ mustache2hs -m Records.hs view/report.mustache Report > $@
Expand Down

0 comments on commit a372318

Please sign in to comment.