Here we describe the essential elements that make up a Wiki Node Server:
Looking at moving the node server forwards from Express 3.0. We ask ourselves:
- What does a Federated Wiki server need to support?
- Are there any aspects of the server that would more rightly belong as part of the client?
First we will look at the routes, and supporting functions, also see source code as at July 2014
app.get ///^((/[a-zA-Z0-9:.-]+/[a-z0-9-]+(_rev\d+)?)+)/?$///, (req, res) ->
This is the main route for initial contact, allowing links to a specific set of pages.
N.B. Only renders the framework, individual pages (json) are fetched and rendered by the client code.
app.get ///([a-z0-9-]+)\.html$///, (req, res, next) ->
Returns a page with the requested fedwiki page rendered on the server. Server rendering does not include the page journal.
Essential for clients that do not support JavaScript, but also for search engines. Those clients that support Javascript will re-render the page, adding the journal.
app.get ///system/factories.json///, (req, res) ->
Returns a JSON structure detailing available plugins (name, title, and category). Used to build the plugin list shown with 'add paragraph'.
app.get ///^/([a-z0-9-]+)\.json$///, cors, (req, res) ->
Returns the JSON for an individual page.
app.get ///^/remote/([a-zA-Z0-9:\.-]+)/([a-z0-9-]+)\.json$///, (req, res) ->
Fetches a page JSON for a remote page.
app.get '/favicon.png', cors, (req,res) ->
Gets a site's favicon.
app.post '/favicon.png', authenticated, (req, res) ->
Used to save a client created favicon.
app.get ///^/remote/([a-zA-Z0-9:\.-]+/favicon.png)$///, (req, res) ->
Fetches the favicon for a remote site.
app.get '/system/slugs.json', cors, (req, res) ->
Returns a list of pages available on server.
app.get '/system/plugins.json', cors, (req, res) ->
Returns a list of installed plugins.
app.get '/system/sitemap.json', cors, (req, res) ->
Returns a sitemap, used by the client for amongst other things searching.
app.put /^\/page\/([a-z0-9-]+)\/action$/i, authenticated, (req, res) ->
perform an edit action on a page – apply a 'add', 'move', 'edit' or 'remove' on page item. Also create a new page, or fork from elsewhere.
Supporting Functions
render = (page) ->
Server side page rendering.
remoteGet = (remote, slug, cb) ->
Fetches page from remote server.
Observations
The current story serialization as a URL has been discussed in issue 412 .
An obvious simplification is to remove those route that are no longer used.
The 'remote' get, both for page json and favicons should be removed.
The following system routes appear not to be used, currently, so could also be removed:
'/system/plugins.json' '/system/slugs.json'
We should remember that server rendering is required for some clients.
The page edit/put mechanism, is at the level of an individual edit to an item. We can't coalesce a group of edits at either the page, or site level, into a less granular change set.
The current regular expressions to identify pages, and sites, is overly restrictive. Confining us to a-z, A-Z, 0-9, and - for page names, and a similar set for site names.
# See also - Anatomy of a Server - DreamFactory Wiki - RESTful Fedwiki Server - Origin Server