purescript-httpurple/docs/Examples/AsyncResponse/Main.purs

35 lines
1.3 KiB
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Examples.AsyncResponse.Main where
2017-09-27 13:55:36 +00:00
import Prelude
import Effect.Console as Console
2017-09-27 13:55:36 +00:00
import HTTPure as HTTPure
import Node.Encoding as Encoding
import Node.FS.Aff as FSAff
-- | Serve the example server on this port
port :: Int
port = 8088
-- | Shortcut for `show port`
portS :: String
portS = show port
-- | The path to the file containing the response to send
filePath :: String
filePath = "./docs/Examples/AsyncResponse/Hello"
-- | Say 'hello world!' when run
sayHello :: HTTPure.Request -> HTTPure.ResponseM
2017-09-27 13:55:36 +00:00
sayHello _ = FSAff.readTextFile Encoding.UTF8 filePath >>= HTTPure.ok
-- | Boot up the server
main :: HTTPure.ServerM
2017-09-27 13:55:36 +00:00
main = HTTPure.serve port sayHello do
Console.log $ " ┌────────────────────────────────────────────┐"
Console.log $ " │ Server now up on port " <> portS <> ""
Console.log $ " │ │"
Console.log $ " │ To test, run: │"
Console.log $ " │ > curl localhost:" <> portS <> " # => hello world! │"
Console.log $ " └────────────────────────────────────────────┘"