import { type RequestEvent } from '@sveltejs/kit'; import type { Handle } from './types.js'; import type { OptionsByStringPath } from '../utils/paths.js'; type MaybePromise = T | Promise; export interface ProxyOptions { to: string; requestHook?: (event: RequestEvent) => MaybePromise; /** * @example * ```ts * tweakResponseHeaders(defaultResponseHeaders) { * defaultResponseHeaders.delete('content-encoding') * defaultResponseHeaders.delete('content-length') * return defaultResponseHeaders * } * ``` */ tweakResponseHeaders?: (defaultResponseHeaders: Headers, options: { request: Request; proxiedUrl?: string; }) => Headers; } /** * Creates a handler which, for requests matching a given path prefix in the given options, proxies * the request to the `to` URL in the corresponding {@link ProxyOptions}. Any path elements after * the matching prefix are preserved, e.g. a request to `/from/some/other/path` will be proxied to * `to/some/other/path`. The request method, body, and headers are preserved, with the exception of * the `Host` header which is set to the proxy target hostname. * * If a `requestHook` is defined, it is called with the original request event before the returned * request is proxied. This allows for modifying the request before it is sent, e.g. to add or * remove authentication headers, api keys, etc. If the returned request is to a URL with the same * origin as the initial request and a path that also starts with the matched path prefix, that * request path is proxied; otherwise, the returned request path is not modified before it is * fetched. If the `requestHook` function throws, the request is not proxied and a response * corresponding to the thrown object (matching Sveltekit endpoint behavior) is returned to the * client instead. * * If multiple options entries would match a request, the first matching entry is used. * * For requests matching a path prefix in options that do not have an `Origin` header or that have * an `Origin` header not matching the request's origin, a 403 Forbidden response is returned. This * prevents use of the proxy by other browser applications, but (IMPORTANT) does not prevent abuse * of the proxy by applications that can set the `Origin` header manually to match. To prevent this, * you can require user authentication and authorization before allowing proxying, validating an * incoming request either in a preceding hook or directly in the `requestHook`. */ export declare function handleProxies(options: OptionsByStringPath): Handle; export {};