Closed rickysullivan closed 5 years ago
I'm writing a /help section for my API.
/help
I wanted to show what roles are assigned to each endpoint.
Is this possible?
const _ = require("lodash"); exports.plugin = { name: "help-plugin", version: "v1", register: server => { server.route({ method: "GET", path: "/help", options: { description: "List all API endpoints", handler: request => { const routes = server.table().map(route => { const { public: { method, path }, settings: { description = "", tags = [] } } = { ...route }; let routeInfo = {}; if ( _.includes(tags, request.auth.isAuthenticated ? "" : "private") || _.includes(tags, "protected") ) { routeInfo = null; } else { routeInfo.method = method.toUpperCase(); routeInfo.path = path; routeInfo.description = description; routeInfo.access = //ROLES TO GO HERE// } return routeInfo; }); return _(routes) .compact() .sortBy("path") .values(); } } }); } };
Before using this plugin, I was defining my auth on each route and grabbing auth.access.scope.required. Now that my ACL is defined at a plugin level, I can't seem to find a way to pull this information.
auth
auth.access.scope.required
I'm writing a
/help
section for my API.I wanted to show what roles are assigned to each endpoint.
Is this possible?
Before using this plugin, I was defining my
auth
on each route and grabbingauth.access.scope.required
. Now that my ACL is defined at a plugin level, I can't seem to find a way to pull this information.