Skip to content

New: Move route definitions to routes.json (fixes #84)#85

Merged
taylortom merged 7 commits intomasterfrom
copilot/refactor-move-route-definitions
Feb 26, 2026
Merged

New: Move route definitions to routes.json (fixes #84)#85
taylortom merged 7 commits intomasterfrom
copilot/refactor-move-route-definitions

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

Route definitions were declared imperatively in setValues() via useDefaultRouteConfig(), manual deletions, and routes.push(). These are migrated to a declarative routes.json consumed by loadRouteConfig (as already adopted by AbstractApiModule and AbstractAuthModule).

Update

  • Removed imperative route setup from setValues(): useDefaultRouteConfig() call, POST / and PUT /:_id deletions, and routes.push() for /install, /:_id/update, /:_id/uses
  • Removed now-unused apidefs import and middleware waitForModule call from setValues()

New

  • routes.json declaring the full route set with useDefaultRoutes: false (POST / and PUT /:_id are excluded per existing behaviour):
{
  "root": "contentplugins",
  "useDefaultRoutes": false,
  "routes": [
    { "route": "/", "handlers": { "get": "default" }, "permissions": { "get": ["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"] } }
  ]
}

Testing

  1. Start the application and confirm contentplugins routes are registered at startup
  2. GET /api/contentplugins — list plugins
  3. POST /api/contentplugins/install — install a plugin via zip upload or version string
  4. POST /api/contentplugins/:_id/update — update a plugin
  5. GET /api/contentplugins/:_id/uses — retrieve plugin usage
  6. Confirm POST / and PUT /:_id are not registered
Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor: Move route definitions to routes.json</issue_title>
<issue_description>## Context

Route definitions are moving from imperative code to declarative routes.json files. The loadRouteConfig function in adapt-authoring-server (PR adapt-security/adapt-authoring-contentplugin#58) now handles reading routes.json, resolving handler strings to bound methods, validating against a schema, and merging with default routes.

AbstractApiModule (PR adapt-security/adapt-authoring-contentplugin#77) and AbstractAuthModule (PR adapt-security/adapt-authoring-contentplugin#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 /:_id from defaults
  • Adds POST /installinstallHandler (permission: install:contentplugins, validate: false)
  • Adds POST /:_id/updateupdateHandler (permission: update:contentplugins)
  • Adds GET /:_id/usesusesHandler (permission: read:contentplugins)

Refactoring steps

  1. Create routes.json in the module root. Since default routes are modified (POST / and PUT /:_id removed), use useDefaultRoutes: false and 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"] }
    }
  ]
}
  1. Remove imperative route setup from init():

    • Remove the useDefaultRouteConfig() call
    • Remove route deletion and push logic
  2. Test by running npm test and verifying routes are registered correctly at startup</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: taylortom <1059083+taylortom@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor route definitions to use routes.json Refactor: Move route definitions to routes.json Feb 26, 2026
@taylortom taylortom changed the title Refactor: Move route definitions to routes.json New: Move route definitions to routes.json (refs #84) Feb 26, 2026
@taylortom taylortom changed the title New: Move route definitions to routes.json (refs #84) New: Move route definitions to routes.json Feb 26, 2026
@taylortom taylortom changed the title New: Move route definitions to routes.json New: Move route definitions to routes.json (fixes #84) Feb 26, 2026
@taylortom taylortom marked this pull request as ready for review February 26, 2026 20:07
…efs #85)

setValues() was missing the loadRouteConfig call so routes.json was
never loaded. Also converts serveSchema from factory to standard handler,
renames handler strings to match method names, adds API metadata from
the removed apidefs.js, and adds adapt-authoring-server peer dependency.
#85)

The override was using res.sendError() instead of next() for error
propagation, and returning the raw schema object instead of schema.built.
Both now match the base class convention in AbstractApiModule.
@taylortom taylortom merged commit b82741f into master Feb 26, 2026
2 checks passed
@taylortom taylortom deleted the copilot/refactor-move-route-definitions branch February 26, 2026 21:36
github-actions bot pushed a commit that referenced this pull request Feb 26, 2026
# [1.5.0](v1.4.0...v1.5.0) (2026-02-26)

### New

* Move route definitions to routes.json (fixes #84) (#85) ([b82741f](b82741f)), closes [#84](#84) [#85](#85)
@github-actions
Copy link

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Move route definitions to routes.json

2 participants