{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Web.Geek.Serve where

import Air.Env
import Hack2
import Hack2.Contrib.Utils (use)
import Web.Geek.Application
import Web.Geek.Config (get_config_from_args)
import Web.Geek.Type

type Port = Int

serve :: [MarkupEngine] -> [Middleware] -> (Application -> Port -> IO ()) -> IO ()
serve _markup_engines middleware_stack server_backend = do
  _config <- get_config_from_args
  geek_app <- initialize_geek _config _markup_engines
  
  let _middleware = use middleware_stack
      _app = _middleware geek_app
      _port = _config.server_port
      
  server_backend _app _port