summaryrefslogtreecommitdiff
path: root/bragi/thermoprint-server/thermoprint-server.hs
blob: 4635dd0aacfce3532efcb6611e066dd6e8f52ae4 (plain)
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
42
43
44
45
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE ImpredicativeTypes #-}

module Main (main) where

import Thermoprint.Server

import Thermoprint.Server.Printer.Generic

import Control.Monad.Trans.Resource
import Control.Monad.Logger
import Control.Monad.Reader

import Data.Function ((&))

import Database.Persist.Postgresql

import qualified Network.Wai.Handler.Warp as Warp

type ServerM = ReaderT ConnectionPool (LoggingT IO)

main :: IO ()
main = thermoprintServer True (Nat runDb) $ configure <$> def `withPrinters` printers'
  where
    runDb :: ServerM a -> IO a
    runDb = runStderrLoggingT . withPostgresqlPool "" 5 . runReaderT

    printers' = [ (pure $ genericPrint "/dev/usb/lp0", def :: QMConfig (ResourceT ServerM))
                ]

    configure c = c
      { queueManagers = queueManagers
      , warpSettings  = warpSettings
      }

    queueManagers _ = QMConfig
      { manager = union [ limitHistorySize 100
                        , limitHistoryAge 3600
                        ]
      , collapse = standardCollapse
      }

    warpSettings = Warp.defaultSettings
      & Warp.setHost "::1"
      & Warp.setPort 8080