6import Data.Maybe (fromMaybe)
8import Effect.Aff.Class (liftAff)
9import Effect.Class (liftEffect)
10import Foreign (unsafeToForeign)
11import Foreign.Object as FObject
12import Promise (Promise)
13import Promise.Aff (fromAff)
14import Yoga.Fastify.Fastify as F
15import Yoga.Fastify.Fastify (Fastify, Port(..), Host(..), RouteURL(..), StatusCode(..))
16import Yoga.Fastify.Om (createOmFastify, getOm, requestParams)
18mkServer :: Effect Fastify
20 fastify <- F.fastify {}
21 omApp <- createOmFastify {} fastify
22 getOm (RouteURL "/users/:id") handleGetUser omApp
25 handleGetUser reply = do
26 params <- requestParams
27 let idStr = fromMaybe "0" (FObject.lookup "id" params)
28 let id = fromMaybe 0 (Int.fromString idStr)
29 let body = unsafeToForeign { id, name: "User " <> idStr }
30 void $ F.status (StatusCode 200) reply # liftEffect
31 void $ F.header "content-type" "application/json" reply # liftEffect
32 F.sendJson body reply # liftAff
34listenServer :: Fastify -> Effect (Promise String)
35listenServer fastify = fromAff $ F.listen { port: Port 44931, host: Host "0.0.0.0" } fastify
37closeServer :: Fastify -> Effect (Promise Unit)
38closeServer fastify = fromAff $ F.close fastify
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list