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

38 lines
1.4 KiB
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Examples.SSL.Main where
2017-07-23 19:17:02 +00:00
import Prelude
import Control.Monad.Eff.Console as Console
import HTTPure as HTTPure
-- | Serve the example server on this port
port :: Int
port = 8085
-- | Shortcut for `show port`
portS :: String
portS = show port
-- | The path to the certificate file
cert :: String
cert = "./docs/Examples/SSL/Certificate.cer"
-- | The path to the key file
key :: String
key = "./docs/Examples/SSL/Key.key"
-- | Say 'hello world!' when run
sayHello :: forall e. HTTPure.Request -> HTTPure.ResponseM e
2017-09-26 06:08:07 +00:00
sayHello _ = HTTPure.ok "hello world!"
2017-07-23 19:17:02 +00:00
-- | Boot up the server
2017-08-02 04:58:11 +00:00
main :: forall e. HTTPure.SecureServerM (console :: Console.CONSOLE | e)
2018-02-09 05:46:45 +00:00
main = HTTPure.serveSecure port cert key sayHello do
2017-07-23 19:17:02 +00:00
Console.log $ " ┌───────────────────────────────────────────┐"
Console.log $ " │ Server now up on port " <> portS <> ""
Console.log $ " │ │"
Console.log $ " │ To test, run: │"
Console.log $ " │ > curl --insecure https://localhost:" <> portS <> ""
Console.log $ " │ # => hello world! │"
Console.log $ " └───────────────────────────────────────────┘"