Skip to content

Instantly share code, notes, and snippets.

@rnons
Created December 23, 2012 07:28
Show Gist options
  • Save rnons/4362471 to your computer and use it in GitHub Desktop.
Save rnons/4362471 to your computer and use it in GitHub Desktop.
Warp: with static subdomain
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.Trans.Resource (ResourceT)
import Filesystem.Path.CurrentOS (decodeString)
import Network.HTTP.Types (status200)
import Network.Wai (responseLBS, rawPathInfo, Request, Response)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
import Network.Wai.Middleware.Vhost (vhost)
import qualified Data.ByteString as S
sayHello :: Request -> ResourceT IO Response
sayHello _ = do
return $ responseLBS status200 [("Content-Type", "text/plain")] "hello"
main :: IO ()
main = do
let settings = defaultFileServerSettings $ decodeString "/srv/http/"
putStrLn $ "http://localhost:3000/"
run 3000 $ vhost
[((S.isPrefixOf "/static/") . rawPathInfo, staticApp settings)
] sayHello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment