We will examine each of the web request handlers that we included in the small implementation of federated wiki. Follow along in the source code. github
See Helpers for definitions used in handlers.
get '/' redirects to welcome-visitors, the only page name deeply wired into federated wiki the same way 'main' is wired into C and Java.
get '/*.json' serves the wiki page who's title has been squeezed into a hyphenated, lowercase, punctuation free version called a 'slug'.
Slugs are filename and url safe and confer case-insensitivity on page titles.
Sinatra will send 404-not-found for missing content which will clue the browser-based version to keep looking elsewhere.
get '/*.html' serves the wiki page fetched as json and translated to html. A helper does just enough to allow navigation through the server's hypertext.
Federation expects us to try harder to find a page which might still be stored on a remote server.
We could proxy to sites mentioned in the page's journal and handle 404s until it is found. But the server handling this request might already be on the wrong side of a firewall to reach the intended content.
get '/view/*' handles a url format preferred by the browser-based implementation. There 'view' means we expect the page from this server. The segment would be replaced with a remote server's domain name if this were not true.