purescript-httpurple/docs/Examples/BinaryResponse/Main.purs
Connor Prussin 6e886b91ac
Add support for non string requests (#184)
* First version of supporting non-string requests

* Clean up

* Minor cleanup

* Simplify to directly export the stream

* Add nl

* Clean up & add more testing

Co-authored-by: sigma-andex <sigma.andex@pm.me>
2021-11-15 20:02:36 -08:00

29 lines
1.1 KiB
Haskell

module Examples.BinaryResponse.Main where
import Prelude
import Effect.Console as Console
import Node.FS.Aff as FS
import HTTPure as HTTPure
-- | The path to the file containing the response to send
filePath :: String
filePath = "./docs/Examples/BinaryResponse/circle.png"
responseHeaders :: HTTPure.Headers
responseHeaders = HTTPure.header "Content-Type" "image/png"
-- | Respond with image data when run
image :: HTTPure.Request -> HTTPure.ResponseM
image = const $ FS.readFile filePath >>= HTTPure.ok' responseHeaders
-- | Boot up the server
main :: HTTPure.ServerM
main =
HTTPure.serve 8080 image do
Console.log $ " ┌──────────────────────────────────────┐"
Console.log $ " │ Server now up on port 8080 │"
Console.log $ " │ │"
Console.log $ " │ To test, run: │"
Console.log $ " │ > curl -o circle.png localhost:8080 │"
Console.log $ " └──────────────────────────────────────┘"