mirror of
https://github.com/snoyberg/keter.git
synced 2024-12-15 01:23:09 +03:00
25f40e1e76
* Disable postgres plugin in foo1_0 example.
38 lines
1.3 KiB
Haskell
38 lines
1.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
import Control.Monad.IO.Class
|
|
import qualified Data.ByteString.Lazy.Char8 as L8
|
|
import Data.Default
|
|
import Network.HTTP.Types
|
|
import Network.Wai
|
|
import Network.Wai.Handler.Warp
|
|
import Network.Wai.Middleware.RequestLogger
|
|
import System.Directory
|
|
import System.Environment
|
|
import System.IO
|
|
|
|
|
|
main :: IO ()
|
|
main = do
|
|
fp <- canonicalizePath "."
|
|
[msg] <- getArgs
|
|
portS <- getEnv "PORT"
|
|
env <- getEnvironment
|
|
let port = read portS
|
|
logger <- mkRequestLogger def
|
|
{ outputFormat = Apache FromHeader
|
|
}
|
|
run port $ logger $ \req send -> do
|
|
liftIO $ putStrLn $ "Received a request at: " ++ show (pathInfo req)
|
|
liftIO $ hFlush stdout
|
|
liftIO $ hPutStrLn stderr $ "Testing standard error"
|
|
liftIO $ hFlush stderr
|
|
send $ responseLBS status200 [("content-type", "text/plain")]
|
|
$ L8.pack $ unlines
|
|
$ ("Message: " ++ msg)
|
|
: ("Path: " ++ fp)
|
|
: ("Headers: " ++ show (requestHeaders req))
|
|
: map (\(k, v) -> concat [ "Env: "
|
|
, k, " = ", v
|
|
]) env
|