Created
December 23, 2012 07:28
-
-
Save rnons/4362471 to your computer and use it in GitHub Desktop.
Warp: with static subdomain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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