Skip to content

Conversation

@mag123c
Copy link
Contributor

@mag123c mag123c commented Sep 16, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #15619

What is the new behavior?

This PR introduces a declarative route rewrite system that allows applications to configure route rewrites at the application level using the routeRewrites option in NestApplicationOptions.

Key Features:

  • Declarative Configuration: Configure route rewrites through application options
  • HTTP Method Support: Specify which HTTP methods to apply rewrites to (or all methods by default)
  • Custom Status Codes: Configure redirect status codes (defaults to 301 Moved Permanently)
  • Global Prefix Integration: Automatically handles global prefix in route paths
  • Performance Optimized: Route rewrites are registered during application startup, not per-request
const app = await NestFactory.create(AppModule, {
  routeRewrites: [
    // Redirect all methods from old path to new path
    { from: '/old-api', to: '/new-api' },

    // Method-specific rewrite with custom status code
    {
      from: '/legacy-users',
      to: '/users',
      methods: RequestMethod.GET,
      statusCode: 302
    },

    // Multiple methods
    {
      from: '/old-posts',
      to: '/posts',
      methods: [RequestMethod.GET, RequestMethod.POST]
    }
  ]
});

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Added private readonly config: ApplicationConfig parameter to enable access to route rewrite configurations

@coveralls
Copy link

Pull Request Test Coverage Report for Build b27093d3-0731-40d7-a3ef-1924c859f223

Details

  • 35 of 35 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 88.779%

Totals Coverage Status
Change from base Build 87823697-4182-4d9a-8625-1cc37cfa7f74: 0.05%
Covered Lines: 7303
Relevant Lines: 8226

💛 - Coveralls

@kamilmysliwiec
Copy link
Member

As I mentioned here #15619 (comment), there's really no need to introduce a new dedicated feature for this when we have a working API in place

@kamilmysliwiec
Copy link
Member

Thanks for your contribution, though. Great work anyway!

@mag123c
Copy link
Contributor Author

mag123c commented Sep 16, 2025

@kamilmysliwiec
While working on it, I kept wondering if I needed this 😄
Thanks for comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants