{-|
  The 'Application' used for the server instance.
-}
app :: ServerOptions -> (ByteString -> ByteString) -> Application
app _ app' request respond
  | rMethod == methodPost =
    logLine ("New POST request from " ++ show (remoteHost request)) ≫
    lazyRequestBody request ≫=
      respond . responseLBS ok200 headers . app'
  | rMethod == methodOptions = respond $ responseLBS ok200 headers "Bring it!"
  | otherwise =
    logLine ("Unhandleable request: " ++ show request) ≫
    respond (responseLBS imATeaPot418 [] "What are you doing to an innocent teapot?")
  where
    rMethod = requestMethod request
    headers = defaultHeaders


{-|
  Run the server.
-}
serve
app :: ServerOptions -> (ByteString -> ByteString) -> Application
app _ app' request respond
  | rMethod == methodPost =
    logLine ("New POST request from " ++ show (remoteHost request)) ≫
    lazyRequestBody request ≫=
      respond . responseLBS ok200 headers . app'
  | rMethod == methodOptions = respond $ responseLBS ok200 headers "Bring it!"
  | otherwise =
    logLine ("Unhandleable request: " ++ show request) ≫
    respond (responseLBS imATeaPot418 [] "What are you doing to an innocent teapot?")
  where
    rMethod = requestMethod request
    headers = defaultHeaders


{-|
  Run the server.
-}
app _ app' request respond
  | rMethod == methodPost =
    logLine ("New POST request from " ++ show (remoteHost request)) ≫
    lazyRequestBody request ≫=
      respond . responseLBS ok200 headers . app'
  | rMethod == methodOptions = respond $ responseLBS ok200 headers "Bring it!"
  | otherwise =
    logLine ("Unhandleable request: " ++ show request) ≫
    respond (responseLBS imATeaPot418 [] "What are you doing to an innocent teapot?")
  where
    rMethod = requestMethod request
    headers = defaultHeaders


{-|
  Run the server.
-}