2017-10-26 21:19:30 +00:00
|
|
|
module Examples.AsyncResponse.Main where
|
2017-09-27 13:55:36 +00:00
|
|
|
|
|
|
|
import Prelude
|
2018-07-08 23:16:48 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
-- | The path to the file containing the response to send
|
|
|
|
filePath :: String
|
|
|
|
filePath = "./docs/Examples/AsyncResponse/Hello"
|
|
|
|
|
|
|
|
-- | Say 'hello world!' when run
|
2018-07-08 23:16:48 +00:00
|
|
|
sayHello :: HTTPure.Request -> HTTPure.ResponseM
|
2018-09-02 21:05:54 +00:00
|
|
|
sayHello = const $ FSAff.readTextFile Encoding.UTF8 filePath >>= HTTPure.ok
|
2017-09-27 13:55:36 +00:00
|
|
|
|
|
|
|
-- | Boot up the server
|
2018-07-08 23:16:48 +00:00
|
|
|
main :: HTTPure.ServerM
|
2021-03-22 19:02:36 +00:00
|
|
|
main =
|
|
|
|
HTTPure.serve 8080 sayHello do
|
|
|
|
Console.log $ " ┌────────────────────────────────────────────┐"
|
|
|
|
Console.log $ " │ Server now up on port 8080 │"
|
|
|
|
Console.log $ " │ │"
|
|
|
|
Console.log $ " │ To test, run: │"
|
|
|
|
Console.log $ " │ > curl localhost:8080 # => hello world! │"
|
|
|
|
Console.log $ " └────────────────────────────────────────────┘"
|