From 1b598d96cafa99da25609125da71d31fbab361bb Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 20 Jan 2016 10:22:51 +0000 Subject: Extended server skeleton up to servant-server --- server/src/Thermoprint/Server.hs | 22 ++++++++++++++++++---- server/thermoprint-server.cabal | 5 ++++- server/thermoprint-server.nix | 6 ++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/server/src/Thermoprint/Server.hs b/server/src/Thermoprint/Server.hs index bba067d..9b8d719 100644 --- a/server/src/Thermoprint/Server.hs +++ b/server/src/Thermoprint/Server.hs @@ -1,9 +1,11 @@ +{-# LANGUAGE RecordWildCards #-} + module Thermoprint.Server ( thermoprintServer - , module Data.Default + , module Data.Default.Class ) where -import Data.Default +import Data.Default.Class import qualified Config.Dyre as Dyre import System.IO (hPutStrLn, stderr) @@ -11,11 +13,20 @@ import System.Exit (exitFailure) import Control.Monad ((<=<)) -data Config = Config { dyreError :: Maybe String +import qualified Network.Wai.Handler.Warp as Warp +import Network.Wai (Application) + +import Servant.Server + +import Thermoprint.API + +data Config = Config { dyreError :: Maybe String + , warpSettings :: Warp.Settings } instance Default Config where def = Config { dyreError = Nothing + , warpSettings = Warp.defaultSettings } thermoprintServer :: Config -> IO () @@ -35,4 +46,7 @@ handleDyreErrors cfg realMain :: Config -> IO () -realMain _ = undefined +realMain cfg@(Config{..}) = Warp.runSettings warpSettings $ serve thermoprintAPI thermoprintServer' + +thermoprintServer :: Server ThermoprintAPI +thermoprintServer = undefined diff --git a/server/thermoprint-server.cabal b/server/thermoprint-server.cabal index cd23251..c8586ae 100644 --- a/server/thermoprint-server.cabal +++ b/server/thermoprint-server.cabal @@ -23,6 +23,9 @@ executable thermoprint-server build-depends: base >=4.8 && <4.9 , thermoprint-spec ==3.0.* , dyre >=0.8.12 && <1 - , data-default -any + , data-default-class >=0.0.1 && <1 + , wai >=3.0.4 && <4 + , servant-server >=0.4.4 && <1 + , warp >=3.1.9 && <4 hs-source-dirs: src default-language: Haskell2010 \ No newline at end of file diff --git a/server/thermoprint-server.nix b/server/thermoprint-server.nix index 4f61c49..7154dc3 100644 --- a/server/thermoprint-server.nix +++ b/server/thermoprint-server.nix @@ -1,4 +1,5 @@ -{ mkDerivation, base, data-default, dyre, stdenv, thermoprint-spec +{ mkDerivation, base, data-default-class, dyre, servant-server +, stdenv, thermoprint-spec, wai, warp }: mkDerivation { pname = "thermoprint-server"; @@ -7,7 +8,8 @@ mkDerivation { isLibrary = false; isExecutable = true; executableHaskellDepends = [ - base data-default dyre thermoprint-spec + base data-default-class dyre servant-server thermoprint-spec wai + warp ]; homepage = "http://dirty-haskell.org/tags/thermoprint.html"; description = "Server for thermoprint-spec"; -- cgit v1.2.3