Class: RouteUtils
Defined in: service-core/src/routes/RouteUtils.ts:22
Provides a set of utilities for converting Route classes to HTTP middleware.
Constructors
Constructor
new RouteUtils():
RouteUtils
Returns
RouteUtils
Methods
checkRequiredPerms()
checkRequiredPerms(
aclUid):RequestHandler
Defined in: service-core/src/routes/RouteUtils.ts:39
Creates a middleware function that verifies the incoming request is from a valid user with at least one of the specified roles.
Parameters
aclUid
string
Returns
checkRequiredRoles()
checkRequiredRoles(
requiredRoles):RequestHandler
Defined in: service-core/src/routes/RouteUtils.ts:66
Creates a middleware function that verifies the incoming request is from a valid user with at least one of the specified roles.
Parameters
requiredRoles
string[]
The list of roles that the authenticated user must have.
Returns
checkRequiredScopes()
checkRequiredScopes(
requiredScopes):RequestHandler
Defined in: service-core/src/routes/RouteUtils.ts:90
Creates a middleware function that verifies the incoming request's token carries at least one of the
specified scopes. This is a coarse, token-level pre-check that runs before the per-resource ACL check —
see RequiresScope.
Parameters
requiredScopes
string[]
The list of scopes of which the authenticated user's token must carry at least one.
Returns
getFuncArray()
getFuncArray(
route,funcs,send?):RequestHandler[]
Defined in: service-core/src/routes/RouteUtils.ts:117
Converts the given array of string or Function objects to functions bound to the given route object.
Parameters
route
any
The route object that the list of functions is bound to.
funcs
(string | Function)[]
The array of functions (or function names) to return.
send?
boolean = false
Set to true to have the last wrapped function send its payload to the client.
Returns
An array of Function objects mapping to the route object.
getRouteMethods()
getRouteMethods(
route):Map<string,any>
Defined in: service-core/src/routes/RouteUtils.ts:140
Searches an route object for any functions that implement a @Method decorator.
Parameters
route
any
The route object to search.
Returns
Map<string, any>
The list of @Method decorated functions that were found.
registerRoute()
registerRoute(
app,route):Promise<void>
Defined in: service-core/src/routes/RouteUtils.ts:169
Registers the provided route object containing a set of decorated endpoints to the server.
Parameters
app
any
The HTTP application/router to register the route to.
route
any
The route object to register.
Returns
Promise<void>
wrapMiddleware()
wrapMiddleware(
obj,func,send?):RequestHandler
Defined in: service-core/src/routes/RouteUtils.ts:360
Wraps the provided function with HTTP handling based on the function's defined decorators.
Parameters
obj
any
The bound object whose middleware function will be wrapped.
func
Function
The decorated function to wrap.
send?
boolean = false
Set to true to have func's result sent to the client.