Created
February 20, 2014 08:51
-
-
Save mxswd/9109451 to your computer and use it in GitHub Desktop.
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
import Web.Scotty.Trans | |
import Network.Wai.Middleware.RequestLogger | |
import Network.Wai.Middleware.Static | |
import Text.Blaze.Html.Renderer.Text (renderHtml) | |
import System.Environment | |
import Database.Persist.Sql (SqlPersistT(..), Connection, runMigration, runSqlPersistM, runSqlConn, unSqlPersistT) | |
import Database.Persist.Postgresql (withPostgresqlConn) | |
setup :: ScottyT Text (SqlPersistT (NoLoggingT (ResourceT IO))) () -> IO () | |
setup m = do | |
withPostgresqlConn connStr $ \conn -> | |
scottyT 3000 (flip runSqlPersistM conn) (flip runSqlPersistM conn) m | |
main :: IO () | |
main = setup $ do | |
middleware logStdoutDev | |
middleware $ staticPolicy (noDots >-> addBase "static") | |
lift (runMigration migrateTables) -- better yet, run this in main before setup. | |
-- users | |
get "/" $ do | |
html $ renderHtml pageIndex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment