Skip to content

Instantly share code, notes, and snippets.

@mdmarek
Created May 21, 2012 02:09
Show Gist options
  • Save mdmarek/2760277 to your computer and use it in GitHub Desktop.
Save mdmarek/2760277 to your computer and use it in GitHub Desktop.
Wai+Warp file server with routes. Used GHC 7.4, Wai 1.1, Warp 1.1 versions.
{-# LANGUAGE OverloadedStrings #-}
-- | Wai+Warp file server with routes. Used GHC 7.4, Wai 1.1, Warp 1.1 versions.
module Main where
import Network.HTTP.Types (status200)
import Network.Wai (Application,responseLBS)
import Network.Wai.Middleware.Router (router,dir)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Application.Static
( StaticSettings(..)
, staticApp
, fileSystemLookup
, defaultWebAppSettings )
-- | Static files application, and the default.
appDefault :: Application
appDefault = staticApp defaultWebAppSettings
{ ssFolder = fileSystemLookup "/home/ubuntu/tomugen.com"
, ssIndices = ["index.html"]
}
-- | Json api application.
appApi :: Application
appApi _ = return $ responseLBS status200
[("Content-Type", "application/json")] "{}"
-- | Routing all API calls to appApi.
app :: Application
app = router [ dir "/api" appApi ] appDefault
-- | Start Warp server on port 8080.
main :: IO ()
main = do
putStrLn $ "http://*:8080/"
run 8080 $ app
@deckool
Copy link

deckool commented Feb 15, 2013

unfortunately i get this error every time and yes, it don't seem to support that, maybe version fault.

[1 of 1] Compiling Main             ( warp-routes.hs, interpreted )

warp-routes.hs:13:5:
    Module
    `Network.Wai.Application.Static'
    does not export
    `fileSystemLookup'
Failed, modules loaded: none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment