import { type ProxyResult, type ProxyConfig, type CreateProxyMiddlewareFn } from '../utils/configure-proxying.js'; import { type RequestHandler, type Response } from 'express'; export declare const X_MOBIFY_REQUEST_CLASS = "x-mobify-request-class"; export declare const X_MOBIFY_QUERYSTRING = "x-mobify-querystring"; export declare const X_MOBIFY_REQUEST_PROCESSOR_LOCAL = "x-mobify-rp-local"; /** * Creates a middleware function that processes incoming requests using a custom request processor. * * This middleware handles: * - Skipping processing for proxy and bundle paths * - Loading and executing custom request processors * - Processing custom query strings from headers * - Removing API Gateway headers * - Enforcing HTTP method restrictions for root path * - Updating request paths and query strings when paths change * * @param requestProcessorPath - Path to the request processor module file * @param proxyConfigs - Array of proxy configurations * @returns Express middleware function * * @example * ```typescript * const middleware = createMRTRequestProcessorMiddleware( * '/path/to/processor.js', * [{ host: 'https://api.example.com', path: 'api' }] * ); * app.use(middleware); * ``` */ export declare const createMRTRequestProcessorMiddleware: (requestProcessorPath: string | undefined, proxyConfigs: ProxyConfig[] | undefined) => RequestHandler; /** * Creates proxy middleware functions for the specified proxy configurations. * * This function creates Express middleware functions that handle proxying requests * to external services. It can optionally create both regular proxy and caching * proxy middlewares for each configuration. The app hostname is automatically * retrieved from environment variables (EXTERNAL_DOMAIN_NAME or defaults to 'localhost:2401'). * * @param proxyConfigs - Array of proxy configurations * @param appProtocol - The protocol to use for the app (defaults to 'http') * @param includeCaching - Whether to include caching proxy middlewares (defaults to false) * @returns Array of proxy middleware results with their paths * * @example * ```typescript * const proxyMiddlewares = createMRTProxyMiddlewares( * [{ host: 'https://api.example.com', path: 'api' }], * 'https', * true // Include caching middlewares * ); * * proxyMiddlewares.forEach(({ fn, path }) => { * app.use(path, fn); * }); * ``` */ export declare const createMRTProxyMiddlewares: (proxyConfigs: ProxyConfig[], appProtocol?: string, includeCaching?: boolean, createProxyFn?: CreateProxyMiddlewareFn, accessControlHeaderForwardingHostnames?: string[], preserveUserAgent?: boolean) => ProxyResult[]; /** * Sets appropriate HTTP headers for local asset files. * * This function sets content-type, caching, and other headers for static assets * served from the local filesystem. It uses the file's modification time for * ETag and Last-Modified headers, and sets no-cache directives for local assets. * * @param res - Express response object * @param assetPath - Path to the asset file * * @example * ```typescript * app.use('/static', express.static('public', { * setHeaders: setLocalAssetHeaders * })); * ``` */ export declare const setLocalAssetHeaders: (res: Response, assetPath: string) => void; /** * Creates an Express static middleware configured for MRT asset serving. * * This function creates a static file serving middleware with MRT-specific * configurations including custom header setting and security options. * * @param staticAssetDir - Directory path containing static assets * @returns Express static middleware function * * @example * ```typescript * const staticMiddleware = createMRTStaticAssetServingMiddleware('/path/to/assets'); * app.use('/static', staticMiddleware); * ``` */ export declare const createMRTStaticAssetServingMiddleware: (staticAssetDir: string) => RequestHandler; /** * Creates a common middleware function that sets the host header based on environment variables. * * The host header is set to EXTERNAL_DOMAIN_NAME if available, otherwise defaults to 'localhost:2401'. * Use this middleware in all environments (local and deployed), at the top of your middleware stack. * * @returns Express middleware function * * @example * ```typescript * const middleware = createMRTCommonMiddleware(); * app.use(middleware); * ``` */ export declare const createMRTCommonMiddleware: () => RequestHandler; /** * Creates a cleanup middleware function that removes internal headers and cleans up request state. * * This middleware performs cleanup operations on requests: * - Removes internal MRT headers (X_MOBIFY_REQUEST_PROCESSOR_LOCAL, X_MOBIFY_QUERYSTRING) * - Removes API Gateway headers that shouldn't be forwarded * - Optionally updates the path and querystring if the request wasn't processed by the request processor * * Use this middleware in all environments (local and deployed), at the end of the middleware chain, * to ensure all internal headers are removed before the request is handled by the application. * * @returns Express middleware function * * @example * ```typescript * const cleanupMiddleware = createMRTCleanUpMiddleware(); * app.use(cleanupMiddleware); * ``` */ export declare const createMRTCleanUpMiddleware: () => RequestHandler;