File: Main.hs

package info (click to toggle)
haskell-snap-server 0.9.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 428 kB
  • sloc: haskell: 4,300; sh: 46; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Blaze.ByteString.Builder
import           Control.Concurrent
import           Control.Exception (finally)

import           Snap.Iteratee
import           Snap.Core
import           Snap.Http.Server

-- FIXME: need better primitives for output
pongServer :: Snap ()
pongServer = modifyResponse $ setResponseBody enum .
                              setContentType "text/plain" .
                              setContentLength 4
  where
    enum = enumBuilder $ fromByteString "PONG"

main :: IO ()
main = do
    m      <- newEmptyMVar
    config <- commandLineConfig defaults
    forkIO $ go m config
    takeMVar m
    return ()

  where
    defaults    = setPort 8000 $
                  setErrorLog ConfigNoLog $
                  setAccessLog ConfigNoLog $
                  setCompression False $
                  setVerbose False $
                  emptyConfig

    go m config = httpServe config pongServer `finally` putMVar m ()