-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathOptions.purs
More file actions
51 lines (42 loc) · 1.34 KB
/
Options.purs
File metadata and controls
51 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Hyper.Node.Server.Options
( defaultOptions
, defaultOptionsWithLogging
, Hostname(..)
, Options(..)
, Port(..)
) where
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (Error)
import Data.Newtype (class Newtype)
import Node.HTTP (HTTP)
import Prelude
newtype Hostname = Hostname String
derive instance newtypeHostname :: Newtype Hostname _
newtype Port = Port Int
derive instance newtypePort :: Newtype Port _
type Options e =
{ hostname :: Hostname
, port :: Port
, onListening :: Hostname -> Port -> Eff (http :: HTTP | e) Unit
, onRequestError :: Error -> Eff (http :: HTTP | e) Unit
, replacePlus :: Boolean
}
defaultOptions :: forall e. Options e
defaultOptions =
{ hostname: Hostname "0.0.0.0"
, port: Port 3000
, onListening: const (const (pure unit))
, onRequestError: const (pure unit)
, replacePlus: true
}
defaultOptionsWithLogging :: forall e. Options (console :: CONSOLE | e)
defaultOptionsWithLogging =
defaultOptions { onListening = onListening
, onRequestError = onRequestError
}
where
onListening (Hostname hostname) (Port port) =
log ("Listening on http://" <> hostname <> ":" <> show port)
onRequestError err =
log ("Request failed: " <> show err)