| 1 |
{-# LANGUAGE OverloadedStrings #-} |
| 2 |
|
| 3 |
module Main where |
| 4 |
|
| 5 |
import ClassicSpec |
| 6 |
import Control.Concurrent |
| 7 |
import Control.Monad |
| 8 |
import qualified Data.ByteString as BS |
| 9 |
import Network.Wai |
| 10 |
import Network.Wai.Application.Classic hiding ((</>)) |
| 11 |
import Network.Wai.Handler.Warp |
| 12 |
import System.Directory |
| 13 |
import System.FilePath |
| 14 |
import Test.Hspec |
| 15 |
import System.Posix |
| 16 |
|
| 17 |
main :: IO () |
| 18 |
main = do |
| 19 |
void $ installHandler sigCHLD Ignore Nothing |
| 20 |
void $ forkIO testServer |
| 21 |
threadDelay 100000 |
| 22 |
hspec spec |
| 23 |
|
| 24 |
testServer :: IO () |
| 25 |
testServer = do |
| 26 |
dir <- getCurrentDirectory |
| 27 |
runSettings settings $ testApp dir |
| 28 |
where |
| 29 |
settings = setPort 2345 $ setHost "127.0.0.1" defaultSettings |
| 30 |
|
| 31 |
testApp :: FilePath -> Application |
| 32 |
testApp dir req |
| 33 |
| cgi = cgiApp appSpec defaultCgiAppSpec cgiRoute req |
| 34 |
| otherwise = fileApp appSpec defaultFileAppSpec fileRoute req |
| 35 |
where |
| 36 |
cgi = "/cgi-bin/" `BS.isPrefixOf` rawPathInfo req |
| 37 |
appSpec = defaultClassicAppSpec { softwareName = "ClassicTester" } |
| 38 |
cgiRoute = CgiRoute { |
| 39 |
cgiSrc = "/cgi-bin/" |
| 40 |
, cgiDst = fromString (dir </> "test/cgi-bin/") |
| 41 |
} |
| 42 |
fileRoute = FileRoute { |
| 43 |
fileSrc = "/" |
| 44 |
, fileDst = fromString (dir </> "test/html/") |
| 45 |
} |