-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
42 lines (34 loc) · 1.15 KB
/
Main.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
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, RecordWildCards, TemplateHaskell
, TypeFamilies, OverloadedStrings, ScopedTypeVariables #-}
module Main where
import Control.Exception (bracket)
import Data.Acid (AcidState, openLocalState)
import Data.Acid.Local (createCheckpointAndClose)
import Happstack.Lite
import Blog.Models
import Blog.Controllers
fileServing :: ServerPart Response
fileServing = serveDirectory EnableBrowsing ["index.html"] "static"
config :: ServerConfig
config =
ServerConfig { port = 8001
, ramQuota = 1 * 10^6
, diskQuota = 20 * 10^6
, tmpDir = "/tmp/"
}
main :: IO ()
main =
do bracket (openLocalState initialBlogState)
(createCheckpointAndClose)
(\acid -> serve (Just config) (blogRoutes acid))
-- Routing
blogRoutes :: AcidState Blog -> ServerPart Response
blogRoutes acid = msum
[
dir "static" $ fileServing,
dir "post" $ postDetail acid,
dir "post2" $ postDetail2 acid,
dir "post3" $ postCrud acid,
dir "edit" $ editPost acid,
homePage acid
]