Host a Website
%feature by ~hanfel-dovned hosts a simple HTML page from an Urbit ship at an associated URL. This tutorial examines how it uses the middleware %schooner library by Quartus to return a web page when contacted by a web browser. You will learn how a basic site hosting app can handle HTTP requests and render a page using an %html mark.
%feature presents a web page from /app/feature-ui at /apps/feature/feature-ui. These paths are both configurable by the developer.
/sur Structure Files
/sur Structure FilesOur primary event in this case is simply an %action to create a page.
/sur/feature.hoon:
|%
+$ action
$% [%new-page html=@t]
==
--No special mark files are necessary for %feature other than %html.
/app Agent Files
/app Agent FilesThe agent only maintains a state containing the page contents as a cord.
The system only handles pokes: there are no subscriptions or Arvo calls except for the Eyre binding.
Pokes
+on-poke only responds to %handle-http-request, which is dealt with in a |^ barket core.
The most interesting part of the whole app is the +handle-http arm:
This arm uses the server and schooner libraries to produce a response of a server state and associated data. HTTP requests to /apps/feature are checked for login authentication, while /apps/feature/public are not.
POST
POSTIn response to a POST request, the default page in the state can be changed. This is the only state change supported by the agent.
GET
GETA GET request defaults to a 404 error.
/apps/feature/publicreturns200success and the default page in the state./apps/featurereturns200success and the target page, statically compiled on agent build.
/lib/schooner
/lib/schoonerThe Schooner library simplifies raw HTTP handling for Gall agents, in particular for MIME returns.
Last updated