2020-05-19 22:56:07 +03:00
|
|
|
/- *landscape
|
2020-04-30 03:41:31 +03:00
|
|
|
/+ *server, default-agent, verb, dbug
|
|
|
|
|%
|
|
|
|
+$ card card:agent:gall
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-zero
|
|
|
|
==
|
|
|
|
::
|
2020-05-19 22:56:07 +03:00
|
|
|
+$ state-zero
|
|
|
|
$: %0
|
|
|
|
=configuration
|
2020-05-21 00:43:15 +03:00
|
|
|
serving=(map url-base=path [clay-base=path public=?])
|
2020-05-19 22:56:07 +03:00
|
|
|
==
|
2020-04-30 03:41:31 +03:00
|
|
|
+$ configuration
|
|
|
|
$: url-prefix=(unit @t)
|
|
|
|
==
|
|
|
|
--
|
|
|
|
%+ verb |
|
|
|
|
%- agent:dbug
|
|
|
|
=| state-zero
|
|
|
|
=* state -
|
|
|
|
^- agent:gall
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
2020-05-21 00:43:15 +03:00
|
|
|
:_ this(serving (~(put by serving) /'~landscape' [/app/landscape %.n]))
|
|
|
|
[%pass /index-bind %arvo %e %connect [~ /] %landscape]~
|
2020-05-06 01:27:39 +03:00
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old-vase=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
[~ this(state !<(state-zero old-vase))]
|
|
|
|
::
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
|^
|
|
|
|
?+ mark (on-poke:def mark vase)
|
2020-05-19 22:56:07 +03:00
|
|
|
%landscape-action
|
|
|
|
(landscape-action !<(action vase))
|
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
%handle-http-request
|
|
|
|
=+ !<([id=@ta req=inbound-request:eyre] vase)
|
|
|
|
:_ this
|
2020-05-19 22:56:07 +03:00
|
|
|
%+ give-simple-payload:app id
|
|
|
|
(handle-http-request req)
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
|
|
|
::
|
2020-05-19 22:56:07 +03:00
|
|
|
++ landscape-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _this)
|
|
|
|
?- -.act
|
|
|
|
%serve-dir
|
2020-05-21 00:43:15 +03:00
|
|
|
?: (~(has by serving) url-base.act)
|
|
|
|
~|("url already bound to {<(~(got by serving) url-base.act)>}" !!)
|
2020-05-19 22:56:07 +03:00
|
|
|
:- ~
|
2020-05-21 00:43:15 +03:00
|
|
|
this(serving (~(put by serving) url-base.act [clay-base.act public.act]))
|
|
|
|
::
|
2020-05-19 22:56:07 +03:00
|
|
|
%unserve-dir
|
2020-05-21 00:43:15 +03:00
|
|
|
[~ this(serving (~(del by serving) url-base.act))]
|
|
|
|
::
|
|
|
|
%toggle-permission
|
|
|
|
?. (~(has by serving) url-base.act)
|
|
|
|
~|("url is not bound" !!)
|
|
|
|
=/ [clay-base=path public=?] (~(got by serving) url-base.act)
|
2020-05-19 22:56:07 +03:00
|
|
|
:- ~
|
2020-05-21 00:43:15 +03:00
|
|
|
this(serving (~(put by serving) url-base.act [clay-base !public]))
|
2020-05-19 22:56:07 +03:00
|
|
|
==
|
|
|
|
::
|
2020-04-30 03:41:31 +03:00
|
|
|
++ handle-http-request
|
|
|
|
|= =inbound-request:eyre
|
|
|
|
^- simple-payload:http
|
2020-05-19 22:56:07 +03:00
|
|
|
=* req request.inbound-request
|
|
|
|
=* headers header-list.req
|
2020-04-30 03:41:31 +03:00
|
|
|
=/ req-line (parse-request-line url.req)
|
2020-05-19 22:56:07 +03:00
|
|
|
?. =(method.req %'GET')
|
|
|
|
not-found:gen
|
|
|
|
=? req-line ?=(~ ext.req-line)
|
|
|
|
[[[~ %html] (snoc site.req-line 'index')] args.req-line]
|
|
|
|
?> ?=(^ ext.req-line)
|
|
|
|
?~ site.req-line
|
|
|
|
not-found:gen
|
2020-04-30 03:41:31 +03:00
|
|
|
=* url-prefix url-prefix.configuration
|
|
|
|
?. ?| ?&(?=(^ url-prefix) =((need url-prefix) i.site.req-line))
|
|
|
|
=(url-prefix ~)
|
|
|
|
==
|
|
|
|
not-found:gen
|
2020-05-19 22:56:07 +03:00
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
?: ?=([%'~landscape' %js %session ~] site.req-line)
|
2020-05-19 22:56:07 +03:00
|
|
|
%+ require-authorization-simple:app
|
|
|
|
inbound-request
|
|
|
|
%- js-response:gen
|
|
|
|
(as-octt:mimes:html "window.ship = '{+:(scow %p our.bowl)}';")
|
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
=/ [payload=simple-payload:http public=?] (get-file req-line)
|
|
|
|
?: public
|
|
|
|
payload
|
|
|
|
(require-authorization-simple:app inbound-request payload)
|
2020-05-19 22:56:07 +03:00
|
|
|
::
|
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
++ get-clay-path
|
2020-05-19 22:56:07 +03:00
|
|
|
|= pax=path
|
2020-05-21 00:43:15 +03:00
|
|
|
^- (unit [path ?])
|
2020-05-19 22:56:07 +03:00
|
|
|
%- ~(rep by serving)
|
2020-05-21 00:43:15 +03:00
|
|
|
|= [[url-base=path clay-base=path public=?] out=(unit [path ?])]
|
2020-05-19 22:56:07 +03:00
|
|
|
?^ out
|
|
|
|
out
|
|
|
|
=/ suf (get-suffix url-base pax)
|
|
|
|
?~ suf ~
|
2020-05-21 00:43:15 +03:00
|
|
|
`[(weld clay-base u.suf) public]
|
2020-05-19 22:56:07 +03:00
|
|
|
::
|
|
|
|
++ get-suffix
|
|
|
|
|= [a=path b=path]
|
|
|
|
^- (unit path)
|
|
|
|
?: (gth (lent a) (lent b))
|
|
|
|
~
|
|
|
|
|-
|
|
|
|
?~ a
|
|
|
|
`b
|
|
|
|
?~ b
|
|
|
|
~
|
|
|
|
?. =(i.a i.b)
|
|
|
|
~
|
|
|
|
%= $
|
|
|
|
a t.a
|
|
|
|
b t.b
|
|
|
|
==
|
|
|
|
::
|
2020-05-21 00:43:15 +03:00
|
|
|
++ get-file
|
2020-05-19 22:56:07 +03:00
|
|
|
|= req-line=request-line
|
2020-05-21 00:43:15 +03:00
|
|
|
^- [simple-payload:http ?]
|
|
|
|
=/ pax=path (snoc site.req-line (need ext.req-line))
|
|
|
|
=/ clay-path=(unit [path ?]) (get-clay-path pax)
|
2020-05-19 22:56:07 +03:00
|
|
|
?~ clay-path
|
2020-05-21 00:43:15 +03:00
|
|
|
[not-found:gen %.n]
|
2020-05-19 22:56:07 +03:00
|
|
|
=/ scry-path
|
|
|
|
:* (scot %p our.bowl)
|
|
|
|
q.byk.bowl
|
|
|
|
(scot %da now.bowl)
|
2020-05-21 00:43:15 +03:00
|
|
|
-.u.clay-path
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
2020-05-19 22:56:07 +03:00
|
|
|
?. .^(? %cu scry-path)
|
2020-05-21 00:43:15 +03:00
|
|
|
[not-found:gen %.n]
|
2020-05-19 22:56:07 +03:00
|
|
|
=/ file (as-octs:mimes:html .^(@ %cx scry-path))
|
2020-05-21 00:43:15 +03:00
|
|
|
:_ +.u.clay-path
|
2020-05-19 22:56:07 +03:00
|
|
|
?+ ext.req-line not-found:gen
|
|
|
|
[~ %html] (html-response:gen file)
|
|
|
|
[~ %js] (js-response:gen file)
|
|
|
|
[~ %css] (css-response:gen file)
|
|
|
|
[~ %png] (png-response:gen file)
|
2020-04-30 03:41:31 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
--
|
|
|
|
::
|
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ path (on-watch:def path)
|
|
|
|
[%http-response *] [~ this]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-arvo
|
|
|
|
|= [=wire sign=sign-arvo]
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ +<.sign (on-arvo:def wire sign)
|
|
|
|
%bound [~ this]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-agent on-agent:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|