From 18d9a4ba0096a2bb0ae615ad0cebdb9fd2c285af Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Fri, 30 Aug 2019 10:56:08 -0400 Subject: [PATCH] A runnable server --- app/Main.hs | 4 +--- src/PaymentServer/Main.hs | 40 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index d4379ac..f0c5b60 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,7 +3,5 @@ module Main ) where import PaymentServer.Main - ( run + ( main -- re-export ) - -main = run diff --git a/src/PaymentServer/Main.hs b/src/PaymentServer/Main.hs index 1e3a2f0..060502b 100644 --- a/src/PaymentServer/Main.hs +++ b/src/PaymentServer/Main.hs @@ -1,6 +1,40 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} + module PaymentServer.Main - ( run + ( main ) where -run :: IO () -run = +import Servant + ( Proxy(Proxy) + , Server + , Application + , serve + , (:>) + ) +import Network.Wai.Handler.Warp + ( run + ) +import PaymentServer.Persistence + ( VoucherDatabase + , memory + ) +import PaymentServer.Processors.Stripe + ( StripeAPI + , stripeServer + ) + +type PaymentServerAPI = "v1" :> "stripe" :> StripeAPI + +paymentServer :: VoucherDatabase d => d -> Server PaymentServerAPI +paymentServer = stripeServer + +paymentServerAPI :: Proxy PaymentServerAPI +paymentServerAPI = Proxy + +paymentServerApp :: VoucherDatabase d => d -> Application +paymentServerApp = (serve paymentServerAPI) . paymentServer + +main :: IO () +main = memory >>= return . paymentServerApp >>= run 8081 -- GitLab