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:
@@ -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,
|
||||
|
||||
+9
-4
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user