link-server-hook: serve static app files from clay
Any requests that aren't explicitly defined endpoints try to load
content from clay instead, but only for html, css and js files.
Depends on
%- parse-request-line
url.request.inbound-request
=* req-head header-list.request.inbound-request
- =- ::TODO =; [cards=(list card) =simple-payload:http]
+ =- ::TODO =;
%+ weld cards
(give-simple-payload:app eyre-id simple-payload)
^- [cards=(list card) =simple-payload:http]
++ handle-post
|= [request-headers=header-list:http =request-line body=(unit octs)]
^- [(list card) simple-payload:http]
- =- ::TODO =; [success=? cards=(list card)]
+ =- ::TODO =;
:- cards
%+ include-cors-headers
request-headers
=/ p=(unit @ud)
%+ biff (~(get by args) 'p')
(curr rush dim:ag)
- ?+ request-line not-found:gen
- ::TODO expose submissions, other data
+ ?+ request-line
+ :: for the default case, try to load file from clay
+ ::
+ ?~ ext.request-line not-found:gen
+ =/ file=(unit octs)
+ ?. ?=([%'~link' *] site.request-line) ~
+ (get-file-at /app/link [t.site u.ext]:request-line)
+ ?~ file not-found:gen
+ ?+ u.ext.request-line not-found:gen
+ %html (html-response:gen u.file)
+ %js (js-response:gen u.file)
+ %css (css-response:gen u.file)
+ ==
:: submissions by recency as json
::
[[[~ %json] [%'~link' %submissions ^]] *]
%local-pages
(snoc path %noun)
==
+::
+++ get-file-at
+ |= [base=path file=path ext=@ta]
+ ^- (unit octs)
+ :: only expose html, css and js files for now
+ ::
+ ?. ?=(?(%html %css %js) ext)
+ ~
+ =/ =path
+ :* (scot %p our.bowl)
+ q.byk.bowl
+ (scot %da now.bowl)
+ (snoc (weld base file) ext)
+ ==
+ ?. .^(? %cu path)
+ ~
+ %- some
+ %- as-octs:mimes:html
+ .^(@ %cx path)
--
\ No newline at end of file
