git.iko.soy/purestack-dev/purescript-purestack-server
on master help sign in
37 lines 1.1 kB history raw
1module Main where
3import Prelude
5import Bun.Server as Bun
6import Data.Maybe (Maybe)
7import Effect (Effect)
8import Effect.Aff (Aff)
9import Effect.Console (log)
10import PureStack.Route (type (/), GET, Headers(..), Middleware, POST)
11import PureStack.Route as Router
12import PureStack.Server as Server
13import Run (AFF, Run(..), runBaseAff)
14import Type.Row (type (+))
16type Foo = { a :: String, b :: Maybe Int, c :: Array Number }
18type API =
19 ( foo :: "foo" / "bar" / Foo / GET Unit { a :: Int, b :: Number, c :: Foo }
20 , bar :: "foo" / Middleware "auth" / "qux" / POST (Headers { foo :: String } Unit) { a :: Int, s :: String }
21 , deep ::
22 "deep" /
23 ( something :: "something" / GET Unit { a :: String }
24 )
25 )
27main :: Effect Unit
28main = do
29 log "🍝"
30 Bun.serve $ Server.run @API identity
31 { handlers:
32 { foo: \x -> pure { a: 1, b: 1.0, c: x }
33 , bar: \i (Headers x _) -> pure { a: 8, s: x.foo }
34 , deep: { something: pure { a: "something" } }
35 }
36 , middlewares: { auth: \req -> pure 1 }
37 }