Main.hs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. {-# OPTIONS -Wall #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3. -- | Main entry point.
  4. module Main (main) where
  5. import Hpaste.Config
  6. import Hpaste.Controller.Activity as Activity
  7. import Hpaste.Controller.Browse as Browse
  8. import Hpaste.Controller.Diff as Diff
  9. import Hpaste.Controller.Home as Home
  10. import Hpaste.Controller.New as New
  11. import Hpaste.Controller.Paste as Paste
  12. import Hpaste.Controller.Raw as Raw
  13. import Hpaste.Controller.Report as Report
  14. import Hpaste.Controller.Reported as Reported
  15. import Hpaste.Controller.Rss as Rss
  16. import Hpaste.Controller.Script as Script
  17. import Hpaste.Model.Announcer (newAnnouncer)
  18. import Hpaste.Types
  19. import Hpaste.Types.Announcer
  20. import Control.Concurrent.Chan (Chan)
  21. import Data.Text.Lazy (Text)
  22. import System.Environment
  23. import Snap.App
  24. import Snap.Http.Server hiding (Config)
  25. import Snap.Util.FileServe
  26. -- | Main entry point.
  27. main :: IO ()
  28. main = do
  29. cpath:_ <- getArgs
  30. config <- getConfig cpath
  31. announces <- newAnnouncer (configAnnounce config)
  32. pool <- newPool (configPostgres config)
  33. setUnicodeLocale "en_US"
  34. httpServe server (serve config pool announces)
  35. where server = setPort 10000 defaultConfig
  36. -- | Serve the controllers.
  37. serve :: Config -> Pool -> Announcer -> Snap ()
  38. serve config pool ans = route routes where
  39. routes = [("/css/",serveDirectory "static/css")
  40. ,("/js/amelie.hs.js",run Script.handle)
  41. ,("/js/",serveDirectory "static/js")
  42. ,("/hs/",serveDirectory "static/hs")
  43. ,("",run (Home.handle False))
  44. ,("/spam",run (Home.handle True))
  45. ,("/:id",run (Paste.handle False))
  46. ,("/raw/:id",run Raw.handle)
  47. ,("/revision/:id",run (Paste.handle True))
  48. ,("/report/:id",run Report.handle)
  49. ,("/reported",run Reported.handle)
  50. ,("/new",run (New.handle New.NewPaste))
  51. ,("/annotate/:id",run (New.handle New.AnnotatePaste))
  52. ,("/edit/:id",run (New.handle New.EditPaste))
  53. ,("/new/:channel",run (New.handle New.NewPaste))
  54. ,("/browse",run Browse.handle)
  55. ,("/activity",run Activity.handle)
  56. ,("/diff/:this/:that",run Diff.handle)
  57. ,("/delete",run Report.handleDelete)
  58. ,("/channel/:channel/rss",run Rss.handle)
  59. ]
  60. run = runHandler ans config pool