-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathController.hs
47 lines (40 loc) · 1.63 KB
/
Controller.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Controller
( withFortuneSearch
, withDevelApp
) where
import FortuneSearch
import Settings
import Yesod.Helpers.Static
import Data.ByteString (ByteString)
import Network.Wai (Application)
import Data.Dynamic (Dynamic, toDyn)
import Database.Redis.Redis (connect,disconnect)
import Data.Pool (createPool)
-- Import all relevant handler modules here.
import Handler.Root
-- This line actually creates our YesodSite instance. It is the second half
-- of the call to mkYesodData which occurs in FortuneSearch.hs. Please see
-- the comments there for more details.
mkYesodDispatch "FortuneSearch" resourcesFortuneSearch
-- Some default handlers that ship with the Yesod site template. You will
-- very rarely need to modify this.
getFaviconR :: Handler ()
getFaviconR = sendFile "image/x-icon" "config/favicon.ico"
getRobotsR :: Handler RepPlain
getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
-- This function allocates resources (such as a database connection pool),
-- performs initialization and creates a WAI application. This is also the
-- place to put your migrate statements to have automatic database
-- migrations handled by Yesod.
withFortuneSearch :: (Application -> IO a) -> IO a
withFortuneSearch f = do
pool <- createPool (connect redisHost redisPort) disconnect 1 120 4
s <- static "/" staticdir
let h = FortuneSearch s pool
toWaiApp h >>= f
withDevelApp :: Dynamic
withDevelApp = toDyn (withFortuneSearch :: (Application -> IO ()) -> IO ())