Export createRateLimitMiddleware from @backstage/backend-defaults/httpRouter (#32789)

When attempting to follow the directions in the [docs to customize the HTTP router](https://backstage.io/docs/backend-system/core-services/http-router/#configuring-the-service), I found that I could not follow them because `createRateLimitMiddleware` was not exported as the code suggested it should be. This patch exports it.

Signed-off-by: Riley Martine <rmartine@integralads.com>
Co-authored-by: Aramis Sennyey <159921952+aramissennyeydd@users.noreply.github.com>
This commit is contained in:
Riley Martine
2026-02-12 03:24:24 -07:00
committed by GitHub
parent a92426920f
commit 5dd683fa0a
4 changed files with 21 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
`createRateLimitMiddleware` is now exported from `@backstage/backend-defaults/httpRouter`
@@ -39,6 +39,12 @@ export function createLifecycleMiddleware(
options: LifecycleMiddlewareOptions,
): RequestHandler;
// @public
export const createRateLimitMiddleware: (options: {
pluginId: string;
config: RootConfigService;
}) => RequestHandler;
// @public
export const httpRouterServiceFactory: ServiceFactory<
HttpRouterService,
@@ -13,15 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NextFunction, Request, Response } from 'express';
import { NextFunction, Request, Response, RequestHandler } from 'express';
import { RateLimitStoreFactory } from '../../../lib/RateLimitStoreFactory.ts';
import { Config } from '@backstage/config';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { rateLimitMiddleware } from '../../../lib/rateLimitMiddleware.ts';
/**
* @public
* Creates a middleware that applies rate limiting to requests based on the provided configuration.
*/
export const createRateLimitMiddleware = (options: {
pluginId: string;
config: Config;
}) => {
config: RootConfigService;
}): RequestHandler => {
const { pluginId, config } = options;
const configKey = `backend.rateLimit.plugin.${pluginId}`;
const enabled = config.has(configKey);
@@ -18,3 +18,4 @@ export { createCredentialsBarrier } from './createCredentialsBarrier';
export { createLifecycleMiddleware } from './createLifecycleMiddleware';
export type { LifecycleMiddlewareOptions } from './createLifecycleMiddleware';
export { createCookieAuthRefreshMiddleware } from './createCookieAuthRefreshMiddleware';
export { createRateLimitMiddleware } from './createRateLimitMiddleware';