generated from mvc-works/calcit-nodejs-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.cljs
59 lines (54 loc) · 1.56 KB
/
router.cljs
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
51
52
53
54
55
56
57
58
59
(ns lilac.router
(:require [lilac.core
:refer
[validate-lilac
deflilac
optional+
keyword+
boolean+
number+
string+
custom+
vector+
list+
record+
not+
and+
set+
nil+
or+
is+]]))
(deflilac
lilac-method+
()
(optional+
(record+
{:code (optional+ (number+)), :type (is+ :file), :file (string+)}
{:check-keys? true})))
(deflilac
lilac-router-path+
()
(record+
{:path (string+),
:get (lilac-method+),
:post (lilac-method+),
:put (lilac-method+),
:delete (lilac-method+),
:next (optional+ (vector+ (lilac-router-path+)))}
{:valid-keys? true}))
(deflilac
lilac-router+
()
(record+ {:port (number+), :routes (vector+ (lilac-router-path+))} {:exact-keys? true}))
(def router-data
{:port 7800,
:routes [{:path "home", :get {:type :file, :file "home.json"}}
{:path "plants/:plant-id",
:get {:type :file, :file "plant-default.json"},
:post {:type :file, :file "ok.json"},
:next [{:path "overview", :get {:type :file, :file "overview.json"}}
{:path "materials/:material-id",
:get {:type :file, :file "materials.json"},
:next [{:path "events",
:get {:type :file, :file "events.json"},
:delete {:code 202, :type :file, :file "ok.json"}}]}]}]})