Setu-TS
    Preparing search index...

    Function Redirect

    • Declares that a handler answers with a redirect: the given status and a Location header.

      It does not short-circuit the handler. A decorator cannot decline to call the method — the plugin invokes it before it can inspect anything it returns — so a @Redirect that claimed to skip the body would be describing a path it does not control. The handler still runs and a plain return is still serialised. That is the point of the declarative form: the handler's work is the side effect, and the redirect is a property of the route.

      A handler that wants to decide per request should call ctx.response.redirect(url) itself through @Params(Ctx()), which terminates the response and returns a HandlerResult.

      status must be an integer in [300, 399], and url must be non-blank and a value the runtime will carry as a Location header — both refused at register() otherwise, for the reason @ResponseHeader validates its own pair: an invalid header value throws while the response headers are written, so every request to the route would answer 500. A blank target is refused separately, because the runtime ACCEPTS it and serves a redirect no client can follow. The same handler may not also carry @HttpCode — both set the status.

      Parameters

      • url: string

        The Location header value

      • status: number = DEFAULT_REDIRECT_STATUS

        The redirect status; 302 by default, matching IResponse.redirect

      Returns SetuMethodDecorator

      A standard method decorator

      At register(), when status is not a redirect status, when url is blank or is not a value the runtime accepts as a header, or when the same handler also carries @HttpCode

      @Controller('/docs')
      class DocsController {
      @Redirect('/docs/v2', 301)
      @Get('/v1')
      legacy(): void {
      this.metrics.recordLegacyHit();
      }
      }

      0.7.0