The last split PR of docs/website/API_V2_PLAN.md § Phase 2. public.routes.js,
player.routes.js and auth.routes.js are deleted; each group is now a directory
whose index.js owns the group gate and the mount table and declares no routes.
Every one of the 200 manifest routes is now in a capability router.
public/ posts (2) wiki (4) pages (2) shard (12) site (4, group root)
player/ account (8) shard (8) appeals (4), behind noindex + requireAuth
auth/ login (2) register (1) invite (2) password (3) session (2, root)
No URL moves. All four gates zero-diff: routes.manifest.json (200 public + 2
internal), routes.guards.json, swagger-output.json (198 operations), and
docs/website/api-route-inventory.json was already in sync. 434 tests green.
Notes on the non-mechanical parts:
- public/index.js and auth/index.js carry no group gate, deliberately, and say
so. The public surface is anonymous by contract (logged-out SPA, Discord bot,
Android ShardStreamClient on /public/shard/stream); /auth is where a caller
becomes authenticated. player/index.js gates on requireAuth only, never
requireRole('player') — staff are a superset of players.
- GET /auth/me has a mount-order dependency: use('/me', meRouter) matches the
bare /me, so the request runs meRouter's noindex + requireAuth and falls
through. session.router.js must stay mounted last. Verified by the
counterfactual — mounting it first still 401s but drops X-Robots-Tag, which
no manifest or guards file can see.
- loginGuards moved to auth/loginGuards.js (frozen) rather than being copied
into the three routers that spread it; sso.routes.js drops its duplicate.
- The :param shadowing check was re-run in dispatch order against the built
stack: 86 routes, 64 literal, none shadowed. /public/wiki/{categories,tags}
ahead of /:slug is the only ordering-sensitive pair.
Co-Authored-By: Claude <noreply@anthropic.com>
57 lines
2.4 KiB
JavaScript
57 lines
2.4 KiB
JavaScript
// Public · Wiki — the published wiki: the page list, categories, tags and a
|
|
// single page by slug. Read-only counterpart of admin/wiki.router.js.
|
|
//
|
|
// Mounted at /api/v1/public/wiki by public/index.js. No group gate; `siteMode`
|
|
// is applied per route.
|
|
//
|
|
// Declaration order is load-bearing: `/categories` and `/tags` are literal paths
|
|
// and MUST stay ahead of `/:slug`, or GET /public/wiki/categories dispatches as a
|
|
// wiki page whose slug is "categories". routes.manifest.json sorts its entries
|
|
// and therefore cannot catch a reordering — the same trap admin/wiki.router.js
|
|
// carries (see docs/website/API_V2_PLAN.md § PR 3).
|
|
|
|
const express = require('express')
|
|
|
|
const ctrl = require('./public.controller')
|
|
const siteMode = require('../../../middleware/siteMode')
|
|
|
|
const wikiRouter = express.Router()
|
|
|
|
wikiRouter.get(
|
|
'/',
|
|
// #swagger.tags = ['Public']
|
|
// #swagger.summary = 'List published wiki pages'
|
|
/* #swagger.responses[200] = { description: 'Published wiki pages', content: { "application/json": { schema: { type: "array", items: { $ref: "#/components/schemas/WikiPage" } } } } } */
|
|
siteMode,
|
|
ctrl.getWikiList,
|
|
)
|
|
// Static paths must precede the :slug route so they aren't captured as a slug.
|
|
wikiRouter.get(
|
|
'/categories',
|
|
// #swagger.tags = ['Public']
|
|
// #swagger.summary = 'List wiki categories'
|
|
/* #swagger.responses[200] = { description: 'Wiki categories', content: { "application/json": { schema: { type: "array", items: { $ref: "#/components/schemas/WikiCategory" } } } } } */
|
|
siteMode,
|
|
ctrl.getWikiCategories,
|
|
)
|
|
wikiRouter.get(
|
|
'/tags',
|
|
// #swagger.tags = ['Public']
|
|
// #swagger.summary = 'List wiki tags'
|
|
/* #swagger.responses[200] = { description: 'Wiki tags', content: { "application/json": { schema: { type: "array", items: { type: "string" } } } } } */
|
|
siteMode,
|
|
ctrl.getWikiTags,
|
|
)
|
|
wikiRouter.get(
|
|
'/:slug',
|
|
// #swagger.tags = ['Public']
|
|
// #swagger.summary = 'Get a single published wiki page'
|
|
// #swagger.parameters['slug'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Wiki page slug.' }
|
|
/* #swagger.responses[200] = { description: 'The wiki page', content: { "application/json": { schema: { $ref: "#/components/schemas/WikiPage" } } } } */
|
|
/* #swagger.responses[404] = { description: 'Not found', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
|
siteMode,
|
|
ctrl.getWikiPage,
|
|
)
|
|
|
|
module.exports = wikiRouter
|