actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
33 lines (32 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.route = void 0;
const index_1 = require("./../index");
var route;
(function (route) {
/**
* Programmatically define a route, rather than using `api.config.routes`. This is useful for plugins which may define routes as well.
* You can use both `api.routes.registerRoute` and `api.config.routes` in the same project.
*
* * method: HTTP verb (get, put, etc)
* * path: The route in question. Can use variables.
* * action: The action to call with this route.
* * apiVersion: The version of the action to call, if more than one.
* * matchTrailingPathParts: Allows the final segment of your route to absorb all trailing path parts in a matched variable. (ie: /api/user would match /api/user/123)
* * dir: Which folder to serve static files from (must by included in api.config.general.paths)
*/
function registerRoute(method, path, action, apiVersion, matchTrailingPathParts = false, dir) {
const verbs = method === "all" ? index_1.api.routes.verbs : [method];
for (const vi in verbs) {
const verb = verbs[vi];
index_1.api.routes.routes[verb].push({
path: path,
matchTrailingPathParts: matchTrailingPathParts,
action: action,
dir: dir,
apiVersion: apiVersion,
});
}
}
route.registerRoute = registerRoute;
})(route = exports.route || (exports.route = {}));