Router & routes
The Router (src/moxie/libraries/modules/router.js) is the source of truth for matching URLs and loading handlers. Route entries live in src/settings/routes/sites/*.js and src/settings/routes/shared.js.
Route entry (typical shape)
'content.spark': {
routes: ['{type}', '{type}/{id}'],
variables: {
type: ['articles', 'images', 'sections', 'tags', 'videos']
},
group: 'content',
specification: 'json-api',
caching: 'standard'
}
| Property | Purpose |
|---|---|
routes |
Path patterns after the site prefix; {token} segments are dynamic. |
variables |
Allowed values for a token; omitted tokens behave as wildcards. |
group |
Extra directory segment under src/apis/... (namespace). |
specification |
Response spec (e.g. json, json-api, mobile, xml) — see src/settings/specs/. |
caching |
Cache policy bucket — see src/settings/caching/. |
framework |
Fallback only when no endpoint index.js exists (often template). |
Resolution order (critical)
For a matched route, the Router builds an API path and tries in order:
apis/{site-or-shared}/{group?}/{api-with-dots-as-slashes}/...- If the route defines a path variable (e.g.
{version}), try.../{variable}/{value}/index.jsfirst. - Fall back to base
.../index.js. - Only if no
index.jsexists, load the route’sframeworkfromframeworks/{framework}/index.js.
Implications:
- If an endpoint
index.jsexists, the route’sframeworkis ignored (Router may log a warning). The effective default is almost always the endpoint’s ownindex.js. - Most routes explicitly set
framework: 'template'as a safety net for template-only endpoints without a custom class.
Shared vs site handlers
- Site-specific routes use handlers under
src/apis/foxnews/,foxbusiness/, etc. - Shared routes use
src/apis/shared/for cross-brand endpoints (articles, videos, search, RSS patterns, etc.).
Adding a new endpoint (checklist)
- Add or extend a route in the correct
src/settings/routes/...file. - Create
src/apis/.../your-endpoint/index.jsexporting a handler withhandle(route, config)(and optionalparse). - Add
config.jsfor querystring defaults andquerystrings.optionsvalidation where needed. - For JSON:API style, add
mapping.jsand optionalhelpers/compute.js,helpers/querystrings.js. - For template output, add
template.dotandconfig.sourcesinconfig.js.
See Frameworks & patterns for file contracts.