• Marks a class as controller.

    Returns ClassDecorator

    The decorator.

    Example

    import { Authorize, Controller, ControllerBase, GET, IHttpRequest, IHttpResponse } from '@egomobile/http-server'

    @Controller()
    @Authorize(['user']) // requires 'user' role
    export default class IndexController extends ControllerBase {
    // use global authorize
    @GET()
    async foo(request: IHttpRequest, response: IHttpResponse) {
    // you can access request.authorizedUser with authorized user
    }

    @GET({
    // define custom validator as filter expression
    //
    // s. https://github.com/m93a/filtrex
    // for more information
    authorize: 'hasRole("admin") and hasHeader("x-my-header", "my-header-value")',
    })
    async bar(request: IHttpRequest, response: IHttpResponse) {
    // you can access request.authorizedUser with authorized user
    }
    }

    // ...
    // your initlaizer script

    // ...

    app.controllers({
    authorize: {
    // try find data for an existing user
    findAuthorizedUser: async (context) => {
    // if there is no matching user, return
    // a falsy value, like (null) or (undefined)

    return {
    roles: roles // an array of roles
    }
    }
    }
    })

    /// ...
  • Parameters

    Returns ClassDecorator

  • Parameters

    Returns ClassDecorator

  • Parameters

    Returns ClassDecorator

Generated using TypeDoc