0 | module Stellar.HTTP
 1 |
 2 | import public Stellar.HTTP.Types
 3 | import Stellar.HTTP.DSL
 4 | import public Stellar.API
 5 | import public Stellar.API.Morphism
 6 | import public Stellar.API.Maybe
 7 |
 8 | import Control.Monad.Continuation
 9 |
10 | import TyTTP
11 | import Node.HTTP
12 | import Node.HTTP.IncomingMessage
13 | import Data.IORef
14 |
15 | import System
16 | import public Stellar.HTTP.Engine
17 |
18 | ||| helper to attach an effectful server with a router
19 | export
20 | attachRouter : {0 a, b : API} -> (router : a =&> All.Maybe b) -> (server : IO $- b =&> End) -> IO $- a =&> End
21 | attachRouter {a, b} router server = map_Lift router
22 |       |&> distribMaybe
23 |       |&> map_Maybe server
24 |       |&> maybeEnd
25 |
26 |
27 | parameters (cfg : ServerConfig)
28 |   ||| Run a server given a costate in PlainHTTP
29 |   export
30 |   http' : Costate (IO $- PlainHTTP) -> IO ()
31 |   http' = http cfg . extract
32 |
33 |   ||| Run a server given a costate in JSONHTTP, ensure each request has a content-type=application/json
34 |   export
35 |   httpJSON : Costate (IO $- JSONHTTP) -> IO ()
36 |   httpJSON m = http' (CheckHeader.execJSON m)
37 |
38 |   ||| Run a server given a costate in JSONHTTP, does not check for content-type
39 |   export
40 |   httpJSONNoCheck : Costate (IO $- JSONHTTP) -> IO ()
41 |   httpJSONNoCheck m = http' (NoCheck.execJSON m)
42 |