Created
December 19, 2017 10:21
-
-
Save vincenthz/a7b2027f8491f685aeeb9d7534dcfd44 to your computer and use it in GitHub Desktop.
serving with warp a index.html and test.wasm
This file contains 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
#!/usr/bin/env stack | |
-- stack --resolver lts-9.17 script --package warp --package wai --package http-types | |
{-# LANGUAGE OverloadedStrings #-} | |
import Network.Wai (responseLBS, responseFile, Application, rawPathInfo) | |
import Network.Wai.Handler.Warp (run) | |
import Network.HTTP.Types (status200, status404) | |
import Network.HTTP.Types.Header (hContentType) | |
main = do | |
let port = 3000 | |
putStrLn $ "Listening on port " ++ show port | |
run port app | |
app :: Application | |
app req f = do | |
case rawPathInfo req of | |
"/" -> f $ responseFile status200 [(hContentType, "text/html")] "index.html" Nothing | |
"/test.wasm" -> f $ responseFile status200 [(hContentType, "application/wasm")] "test.wasm" Nothing | |
_ -> f $ responseLBS status404 [(hContentType, "text/plain")] "Unknown path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment