diff options
Diffstat (limited to 'bragi/thermoprint-server')
-rw-r--r-- | bragi/thermoprint-server/thermoprint-server.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/bragi/thermoprint-server/thermoprint-server.hs b/bragi/thermoprint-server/thermoprint-server.hs new file mode 100644 index 00000000..4635dd0a --- /dev/null +++ b/bragi/thermoprint-server/thermoprint-server.hs | |||
@@ -0,0 +1,45 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | {-# LANGUAGE ImpredicativeTypes #-} | ||
3 | |||
4 | module Main (main) where | ||
5 | |||
6 | import Thermoprint.Server | ||
7 | |||
8 | import Thermoprint.Server.Printer.Generic | ||
9 | |||
10 | import Control.Monad.Trans.Resource | ||
11 | import Control.Monad.Logger | ||
12 | import Control.Monad.Reader | ||
13 | |||
14 | import Data.Function ((&)) | ||
15 | |||
16 | import Database.Persist.Postgresql | ||
17 | |||
18 | import qualified Network.Wai.Handler.Warp as Warp | ||
19 | |||
20 | type ServerM = ReaderT ConnectionPool (LoggingT IO) | ||
21 | |||
22 | main :: IO () | ||
23 | main = thermoprintServer True (Nat runDb) $ configure <$> def `withPrinters` printers' | ||
24 | where | ||
25 | runDb :: ServerM a -> IO a | ||
26 | runDb = runStderrLoggingT . withPostgresqlPool "" 5 . runReaderT | ||
27 | |||
28 | printers' = [ (pure $ genericPrint "/dev/usb/lp0", def :: QMConfig (ResourceT ServerM)) | ||
29 | ] | ||
30 | |||
31 | configure c = c | ||
32 | { queueManagers = queueManagers | ||
33 | , warpSettings = warpSettings | ||
34 | } | ||
35 | |||
36 | queueManagers _ = QMConfig | ||
37 | { manager = union [ limitHistorySize 100 | ||
38 | , limitHistoryAge 3600 | ||
39 | ] | ||
40 | , collapse = standardCollapse | ||
41 | } | ||
42 | |||
43 | warpSettings = Warp.defaultSettings | ||
44 | & Warp.setHost "::1" | ||
45 | & Warp.setPort 8080 | ||