No description
  • TypeScript 98.2%
  • JavaScript 1.8%
Find a file
2026-02-06 20:34:41 -08:00
.gitignore Initial commit 2026-02-06 20:25:14 -08:00
example.controller.ts Initial commit 2026-02-06 20:25:14 -08:00
example.module.ts Initial commit 2026-02-06 20:25:14 -08:00
generate-get-routes.decorator.test.ts Initial commit 2026-02-06 20:25:14 -08:00
generate-get-routes.decorator.ts Initial commit 2026-02-06 20:25:14 -08:00
jest.config.js Initial commit 2026-02-06 20:25:14 -08:00
main.ts Initial commit 2026-02-06 20:25:14 -08:00
package-lock.json Initial commit 2026-02-06 20:25:14 -08:00
package.json Add readme 2026-02-06 20:27:28 -08:00
README.md Fix the README example 2026-02-06 20:34:41 -08:00
tsconfig.json Initial commit 2026-02-06 20:25:14 -08:00

NestJS Generated Routes Example

Example demonstrating dynamic route generation with NestJS decorators.

Overview

This project shows how to use a custom @GenerateGetRoutes decorator to automatically create GET endpoints from a configuration object, reducing boilerplate code.

Installation

npm install

Running the Application

npm start

The server will start on http://localhost:3000.

Running Tests

npm test

Usage

Define routes as a data object and apply the decorator to your controller:

import { Controller } from '@nestjs/common';
import { GenerateGetRoutes, RoutesData } from './generate-get-routes.decorator';

const staticRoutes: RoutesData = {
  health: {
    path: 'health',
    response: { status: 'ok', timestamp: new Date().toISOString() },
  },
  version: {
    path: 'version',
    response: { version: '1.0.0', build: '12345' },
  },
  config: {
    path: 'config',
    response: { env: 'development', debug: true },
  },
};

@GenerateGetRoutes(staticRoutes)
@Controller('example')
export class ExampleController {}

This automatically creates:

  • GET /example/health{ status: 'ok', timestamp: '...' }
  • GET /example/version{ version: '1.0.0', build: '12345' }
  • GET /example/config{ env: 'development', debug: true }