2018-08-30 22:01:49 +00:00
|
|
|
module Examples.Binary.Main where
|
2018-08-20 02:50:07 +00:00
|
|
|
|
|
|
|
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
|
2018-08-30 22:01:49 +00:00
|
|
|
filePath = "./docs/Examples/Binary/circle.png"
|
2018-08-20 02:50:07 +00:00
|
|
|
|
2018-09-02 21:05:54 +00:00
|
|
|
responseHeaders :: HTTPure.Headers
|
|
|
|
responseHeaders = HTTPure.header "Content-Type" "image/png"
|
|
|
|
|
2018-08-20 02:50:07 +00:00
|
|
|
-- | Respond with image data when run
|
|
|
|
image :: HTTPure.Request -> HTTPure.ResponseM
|
2018-09-02 21:05:54 +00:00
|
|
|
image = const $ FS.readFile filePath >>= HTTPure.ok' responseHeaders
|
2018-08-20 02:50:07 +00:00
|
|
|
|
|
|
|
-- | Boot up the server
|
|
|
|
main :: HTTPure.ServerM
|
2021-03-22 19:02:36 +00:00
|
|
|
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 $ " └──────────────────────────────────────┘"
|