Skip to content

RouteInfo

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/middleware/middleware-configuration.interface.ts

Part of: Common

RouteInfo describes a single route targeted by middleware configuration. It combines the route path, HTTP request method, and API version so middleware can be applied to the correct endpoint variant.

Properties

PropertyType
pathstring
methodRequestMethod
versionVersionValue

Diagram

mermaid
graph LR
  Middleware[Middleware Configuration] --> RouteInfo
  RouteInfo --> Path[path: string]
  RouteInfo --> Method[method: RequestMethod]
  RouteInfo --> Version[version: VersionValue]
  RouteInfo --> TargetRoute[Versioned HTTP Route]

Usage

ts
import { RequestMethod } from '@nestjs/common';
import type { RouteInfo } from './middleware-configuration.interface';

const protectedRoute: RouteInfo = {
  path: 'users/:id',
  method: RequestMethod.GET,
  version: '1',
};

// Example: register middleware for a specific versioned endpoint.
consumer
  .apply(AuthMiddleware)
  .forRoutes(protectedRoute);

AI Coding Instructions

  • Provide all three fields when creating a RouteInfo: path, method, and version.
  • Use RequestMethod enum values instead of raw HTTP method strings such as 'GET'.
  • Keep path consistent with the application's route definitions, including parameter segments like :id.
  • Set version to the same VersionValue used by the controller or route being targeted.
  • Use RouteInfo when middleware must apply to a specific method and API version rather than an entire controller.

Used by

5 references from 5 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (5)

  • MiddlewareBuilderpackages/core/middleware/builder.ts:17
  • handlerpackages/core/middleware/middleware-module.ts:287
  • RouteInfoPathExtractorpackages/core/middleware/route-info-path-extractor.ts:16
  • modulesContainerpackages/core/middleware/routes-mapper.ts:148
  • anonymousMiddlewarepackages/core/middleware/utils.ts:77

Was this page helpful?

Download as PDF
RouteInfo — NestJS head-to-head