Skip to content

Instantly share code, notes, and snippets.

@deckool
Last active December 14, 2015 02:09
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 deckool/5011659 to your computer and use it in GitHub Desktop.
Save deckool/5011659 to your computer and use it in GitHub Desktop.
top server side routing using Snap
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Snap.Core
import Snap.Util.FileServe
import Snap.Http.Server
main :: IO ()
main = do
httpServe (setPort 80 defaultConfig) skite
-- Applications for each site
site1 :: Snap ()
site1 = route [ ("/", ifTop $ serveDirectory "site1")
, ("yst", serveDirectory "site1/folder")
-- and this can go on and on
]
skite :: Snap ()
skite = do
req <- fmap rqServerName getRequest
routes req
where
routes req =
if (req == "www.site1.ro") then (site1) else pass <|>
if (req == "site1.ro") then (site1) else pass <|>
if (req == "www.site2.ro") then (writeBS req) else pass <|>
if (req == "site2.ro") then (writeBS "Nowhere to be found") else pass <|>
ifTop (writeBS req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment