summaryrefslogtreecommitdiff
path: root/bragi/thermoprint-server
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-14 17:28:37 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-14 17:28:37 +0100
commite100119827474928636c2ed9a9772f3c5107663b (patch)
tree80833a41f9f067125fea734b134b0a9424fd7159 /bragi/thermoprint-server
parent000d46fbd462dc59aa143261b894f9c470e54040 (diff)
parentf655f88cbbc334ad56a79c2287f18defa5aa98ba (diff)
downloadnixos-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.hs45
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
4module Main (main) where
5
6import Thermoprint.Server
7
8import Thermoprint.Server.Printer.Generic
9
10import Control.Monad.Trans.Resource
11import Control.Monad.Logger
12import Control.Monad.Reader
13
14import Data.Function ((&))
15
16import Database.Persist.Postgresql
17
18import qualified Network.Wai.Handler.Warp as Warp
19
20type ServerM = ReaderT ConnectionPool (LoggingT IO)
21
22main :: IO ()
23main = 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