-
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
ContentPluginModule calls useDefaultRouteConfig() then:
- Removes POST
/and PUT/:_idfrom defaults - Adds POST
/install→installHandler(permission:install:contentplugins,validate: false) - Adds POST
/:_id/update→updateHandler(permission:update:contentplugins) - Adds GET
/:_id/uses→usesHandler(permission:read:contentplugins)
Refactoring steps
- Create
routes.jsonin the module root. Since default routes are modified (POST/and PUT/:_idremoved), useuseDefaultRoutes: falseand declare the full set:
{
"root": "contentplugins",
"useDefaultRoutes": false,
"routes": [
{
"route": "/",
"handlers": { "get": "default" },
"permissions": { "get": ["read:{scope}"] }
},
{
"route": "/schema",
"handlers": { "get": "serveSchema" },
"permissions": { "get": ["read:schema"] }
},
{
"route": "/:_id",
"handlers": { "get": "default", "patch": "default", "delete": "default" },
"permissions": { "get": ["read:{scope}"], "patch": ["write:{scope}"], "delete": ["write:{scope}"] }
},
{
"route": "/query",
"validate": false,
"modifying": false,
"handlers": { "post": "query" },
"permissions": { "post": ["read:{scope}"] }
},
{
"route": "/install",
"validate": false,
"handlers": { "post": "installHandler" },
"permissions": { "post": ["install:contentplugins"] }
},
{
"route": "/:_id/update",
"handlers": { "post": "updateHandler" },
"permissions": { "post": ["update:contentplugins"] }
},
{
"route": "/:_id/uses",
"handlers": { "get": "usesHandler" },
"permissions": { "get": ["read:contentplugins"] }
}
]
}-
Remove imperative route setup from
init():- Remove the
useDefaultRouteConfig()call - Remove route deletion and push logic
- Remove the
-
Test by running
npm testand verifying routes are registered correctly at startup
Reactions are currently unavailable