Skip to content

Commit

Permalink
near-gateways work on ui setup
Browse files Browse the repository at this point in the history
  • Loading branch information
YunPearce committed Feb 7, 2024
1 parent 1da6ca4 commit 9f39570
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 28 deletions.
94 changes: 75 additions & 19 deletions desk/app/near-gateways.hoon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/- *near-handler
/+ dbug, default-agent, *near-handler, gossip, server, schooner
/+ dbug, default-agent, *near-handler, gossip, server, schooner, verb
/$ grab-metadata %noun %near-metadata
::
|%
Expand All @@ -11,6 +11,7 @@
+$ state-0
$: %0
:: (map identifier=[ship id] metadata=[name url])
ui-glob=[identifier glob]
heard=(map identifier metadata)
published=(map identifier metadata)
installed=(map identifier glob)
Expand All @@ -22,6 +23,9 @@
=| state-0
=* state -
::
::
%+ verb |
%- agent:dbug
%- %+ agent:gossip
[2 %anybody %anybody |]
%+ ~(put by *(map mark $-(* vase)))
Expand Down Expand Up @@ -89,8 +93,11 @@
::
++ init
^+ that
%- emit
%- emil
:~
[%pass /eyre/connect %arvo %e %connect [~ /apps/near] %near-gateways]
[%pass /publish-ui %agent [our.bowl %near-gateways] %poke %near-action !>([%publish 'ui-main' url])]
==
::
++ load
|= vaz=vase
Expand All @@ -109,12 +116,16 @@
%near-action
?> from-self
=+ !<(act=gateway-action vase)
~& >>> act
?- -.act
::
%publish
?~ (find ~[metadata.act] ~(val by published))
=/ id=identifier [our.bowl (sham eny.bowl)]
?: =(metadata.act ['ui-main' url])
=. ui-glob [id *glob]
%+ get-gateway-glob
metadata.act
id
=. published (~(put by published) id metadata.act)
%+ get-gateway-glob
metadata.act
Expand All @@ -134,6 +145,7 @@
^+ that
=/ req=request-line:server (parse-request-line:server url.request)
=+ send=(cury response:schooner id)
~& >>> req
?. authenticated
%- emil
%- send
Expand All @@ -144,13 +156,23 @@
%'GET'
?+ [site ext]:req
%- emil
%- send [302 ~ [%redirect '../near']]
%- send [302 ~ [%redirect '../']]
[[%apps %near ~] *]
%- emil
%+ give-simple-payload:app:server
id
%- from-ui-glob
req(site /index/html)
::
[[%apps %near ~] *]
%- emil
%- send [200 ~ [%plain "welcome to %near-gateway"]] ::for now
[[%apps %near %assets *] *]
=/ new-site (weld (slag 2 site.req) (drop ext.req))
%- emil
%+ give-simple-payload:app:server
id
%- from-ui-glob
req(site new-site)
::
[[%apps %near @ @ *] *]
[[%apps %near @ @ *] *]
?. (gte (lent site.req) 5)
%- emil
%- send dump
Expand All @@ -159,15 +181,12 @@
?. (~(has by installed) identifier)
%- emil
%- send dump
~& > ['hash' (sham (~(get by installed) identifier))]
=/ new-site
%+ weld
%+ slag 4
;; (list @ta) site.req
%- drop
ext.req
~& > req
~& >> ['site' (weld (slag 4 `(list @ta)`site.req) (drop ext.req))]
%- emil
%+ give-simple-payload:app:server
id
Expand All @@ -181,11 +200,23 @@
%- send dump
==
::
++ from-ui-glob
|= request=request-line:server
^- simple-payload:http
=/ requested ?: (~(has by +.ui-glob) site.request)
site.request
/index/html
=/ =mime (~(got by +.ui-glob) requested)
=/ mime-type=@t (rsh 3 (crip <p.mime>))
=; headers
[[200 headers] `q.mime]
:- content-type+mime-type
?: =(/index/html requested) ~
~[max-1-wk:gen:server]
::
++ from-glob
|= [identifier=[=ship id=@uvH] request=request-line:server]
^- simple-payload:http
~& > request
~& (~(has by installed) identifier)
?. (~(has by installed) identifier) not-found:gen:server
=/ =glob (~(got by installed) identifier)
=/ requested ?: (~(has by glob) site.request)
Expand Down Expand Up @@ -222,7 +253,7 @@
==
::
++ watch
|= =path
|= =path
^+ that
?+ path ~|(bad-watch-path+path !!)
[%http-response *]
Expand All @@ -241,6 +272,15 @@
|= [=wire =sign:agent:gall]
^+ that
?+ wire ~|(bad-agent-wire+wire !!)
[%publish-ui ~]
?+ -.sign ~|([%unexpected-self-poke-sign -.sign] !!)
%poke-ack
?~ p.sign
that
~& 'Poke ui failed'
that
==
::
[%~.~ %gossip %gossip ~]
?+ -.sign ~|([%unexpected-gossip-sign -.sign] !!)
%fact
Expand Down Expand Up @@ -271,13 +311,16 @@
%thread-done
=/ glob !<(glob q.cage.sign)
=/ id (id-from-wire wire)
=/ had=metadata (~(got by published) id)
:: =/ had=metadata (~(got by published) id)
=/ path ;; (list @ta) wire
=/ got=metadata
:- (snag 2 path)
(snag 3 path)
?. =(url.had url.got)
~& >>> 'Glob url mismatch'
:: ?. =(url.had url.got)
:: ~& >>> 'Glob url mismatch'
:: that
?: =(got ['ui-main' url])
=. ui-glob [-.ui-glob glob]
that
~& > 'Gateway globbed successfully'
=. installed (~(put by installed) id glob)
Expand All @@ -286,7 +329,7 @@
%metadata
!> ^- [identifier metadata]
[id got]
==
==
==
==
::
Expand All @@ -311,9 +354,22 @@
|= =path
^- (unit (unit cage))
?+ path [~ ~]
:: add dbug mime pretty printer
::
[%x %heard ~] ``json+!>((id-data:enjs heard))
[%x %published ~] ``json+!>((id-data:enjs published))
[%x %installed ~] ``json+!>((id-glob:enjs ~(tap in ~(key by installed))))
[%x %dbug %state ~]
=- ``noun+!>(-)
%_ state
installed
%- ~(run by installed)
|= =glob
%- ~(run by glob)
|=(=mime mime(q.q 1.337))
+.ui-glob
%- ~(run by +.ui-glob)
|=(=mime mime(q.q 1.337))
==
==
++ url 's3-bucket-near-gateways-ui-url'
--
10 changes: 10 additions & 0 deletions desk/desk.docket-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:~
title+'near-gateway'
info+'NEAR gateway manager'
color+0xa6.7bc4
base+'near'
site+/apps/near
version+[0 0 1]
website+'https://github.com/urbit'
license+'MIT'
==
Loading

0 comments on commit 9f39570

Please sign in to comment.