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
|
|
|
|
|
|
|
|
-- | Serve the example server on this port
|
|
|
|
port :: Int
|
|
|
|
port = 8090
|
|
|
|
|
|
|
|
-- | Shortcut for `show port`
|
|
|
|
portS :: String
|
|
|
|
portS = show port
|
|
|
|
|
|
|
|
-- | 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
|
|
|
|
|
|
|
-- | Respond with image data when run
|
|
|
|
image :: HTTPure.Request -> HTTPure.ResponseM
|
2018-08-27 04:54:04 +00:00
|
|
|
image _ = FS.readFile filePath >>= HTTPure.ok' headers
|
2018-08-20 02:50:07 +00:00
|
|
|
where
|
|
|
|
headers = HTTPure.header "Content-Type" "image/png"
|
|
|
|
|
|
|
|
-- | Boot up the server
|
|
|
|
main :: HTTPure.ServerM
|
|
|
|
main = HTTPure.serve port image do
|
|
|
|
Console.log $ " ┌────────────────────────────────────────────┐"
|
|
|
|
Console.log $ " │ Server now up on port " <> portS <> " │"
|
|
|
|
Console.log $ " │ │"
|
|
|
|
Console.log $ " │ To test, run: │"
|
|
|
|
Console.log $ " │ > curl -o circle.png localhost:" <> portS <> " │"
|
|
|
|
Console.log $ " └────────────────────────────────────────────┘"
|