summaryrefslogtreecommitdiff
path: root/desk/lib/rout.hoon
blob: a818ec61ef6c983a9c750f1c704cd572008e64f2 (plain)
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
/+  *sortug
|%
+$  card  card:agent:gall
+$  eyre-poke  [id=@da req=inbound-request:eyre]
::  our paths are particular
+$  paeth  (list @t)
+$  req-path   [=method:http paeth]
+$  route-map  (map req-path simple-payload:http)
+$  data   [=order state=mold]
:: I'd rather it can be a non-simple payload but whatever
+$  route  $-(inbound-request route-end)
++  de-path
::   modified from apat:de-purl:html
=/  delim  ;~(pose fas dot)
%+  cook  :: get rid of the last dot and make the extension a part of the path
|=  l=paeth  ^+  l
=/  acc  [nl=*_l i=1]
%^  spin  l  acc
|=  [e=@t a=acc]
:-  e  :_  +(i)
::  only change the last one
?.  .=(i (lent l))  a.a
(rash last (csplit dot))
;~(pfix fas (more fas smeg:de-purl:html))

++  parse-url-path
  |=  url=@t
  ^-  request-line
  (fall (rush url ;~(plug de-path yque:de-purl:html)) [[~ ~] ~])
++  $  =state
  |*  state-type=mold
  
=/  met  method.request.req.order
=/  req-line  (parse-request-line url.request.req.order)
=/  pth=path  :-  met  site.req-line
?+  pth  :_  state  (serve-404 req-line)
  [%'GET' ~ ~]        :_  state  (serve-index req-line)  ::  "/"
  [%'GET' @ @ @ @ *]  :_  state  (serve-post site.req-line)  
  [%'POST' *]         (handle-post req-line body.request.req.order state)
  :: [%get %blog *]      serve-blog
  :: [%get 'chat' *]   serve-chat
  :: [%get 'forum' *]  serve-forum
  :: [%get 'about' *]  serve-about
==

:: The api we want is
(route eyre-poke route-map state bowl)
::  route-map is 
+
:: and from that we get
[(list card) simple-payload:http _state]
which the router itself resolves to (quip card _state)
--