Skip to content

Instantly share code, notes, and snippets.

@banacorn
Created August 5, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banacorn/6158222 to your computer and use it in GitHub Desktop.
Save banacorn/6158222 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Network.Wai (requestHeaders, pathInfo)
import Data.Text (intercalate, unpack)
import Data.Text.Encoding (decodeUtf8)
import Data.Text.Lazy (fromStrict)
import Network.Mime (defaultMimeLookup)
import Control.Applicative ((<$>))
import Control.Monad.Trans (liftIO)
main = scotty 3000 $ do
get anything $ do
referer <- getReferer
path <- getPath
case referer of
Nothing -> file "index.html"
Just _ -> do
header "Content-Type" (lookupMime path)
file (unpack path)
where
getReferer = lookup "Referer" <$> requestHeaders <$> request
getPath = intercalate "/" <$> pathInfo <$> request
lookupMime = fromStrict . decodeUtf8 . defaultMimeLookup
-- matches anything
anything = function . const . Just $ []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment