-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
Description
Context
Route definitions are moving from imperative code to declarative routes.json files. The loadRouteConfig function in adapt-authoring-server (PR #58) now handles reading routes.json, resolving handler strings to bound methods, validating against a schema, and merging with default routes.
AbstractApiModule (PR #77) and AbstractAuthModule (PR #68) both call loadRouteConfig in setValues() with a defaults option, so consumer modules that provide a routes.json automatically get the base default routes prepended.
Current state
UsersModule calls useDefaultRouteConfig(), then:
- Removes POST
/from the default routes - Prepends a
/meroute with GET/PUT/PATCH →requestHandler()(permissions:read:me,write:me)
Refactoring steps
- Create
routes.jsonin the module root. Since this module removes POST from/and adds/me, the full routes need to be declared withuseDefaultRoutes: false:
{
"root": "users",
"useDefaultRoutes": false,
"routes": [
{
"route": "/me",
"handlers": { "get": "default", "put": "default", "patch": "default" },
"permissions": { "get": ["read:me"], "put": ["write:me"], "patch": ["write:me"] }
},
{
"route": "/",
"handlers": { "get": "default" },
"permissions": { "get": ["read:{scope}"] }
},
{
"route": "/schema",
"handlers": { "get": "serveSchema" },
"permissions": { "get": ["read:schema"] }
},
{
"route": "/:_id",
"handlers": { "put": "default", "get": "default", "patch": "default", "delete": "default" },
"permissions": { "put": ["write:{scope}"], "get": ["read:{scope}"], "patch": ["write:{scope}"], "delete": ["write:{scope}"] }
},
{
"route": "/query",
"validate": false,
"modifying": false,
"handlers": { "post": "query" },
"permissions": { "post": ["read:{scope}"] }
}
]
}-
Remove imperative route setup from
init():- Remove the
useDefaultRouteConfig()call - Remove the route filter/splice logic
- Remove the
/meroute push
- Remove the
-
Test by running
npm testand verifying routes are registered correctly at startup
Reactions are currently unavailable