diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 17:28:37 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 17:28:37 +0100 |
commit | e100119827474928636c2ed9a9772f3c5107663b (patch) | |
tree | 80833a41f9f067125fea734b134b0a9424fd7159 /bragi/thermoprint-server | |
parent | 000d46fbd462dc59aa143261b894f9c470e54040 (diff) | |
parent | f655f88cbbc334ad56a79c2287f18defa5aa98ba (diff) | |
download | nixos-e100119827474928636c2ed9a9772f3c5107663b.tar nixos-e100119827474928636c2ed9a9772f3c5107663b.tar.gz nixos-e100119827474928636c2ed9a9772f3c5107663b.tar.bz2 nixos-e100119827474928636c2ed9a9772f3c5107663b.tar.xz nixos-e100119827474928636c2ed9a9772f3c5107663b.zip |
Merge branch 'master' of git:nixos
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 | ||