diff --git a/src/core.ts b/src/core.ts index a2d973d..d101afa 100644 --- a/src/core.ts +++ b/src/core.ts @@ -9,7 +9,7 @@ export interface ProxyParty { handler?: DefineProxyPartyHandler pathRewrite?: { [s: string]: string } | ((path: string) => string) enableLogger?: boolean - proxyOptions?: ProxyOptions + proxyOptions?: ProxyOptions | ((event: H3Event) => ProxyOptions) } export const defineProxyParty = (proxies: ProxyParty[]) => proxies diff --git a/src/runtime/server/plugin.ts b/src/runtime/server/plugin.ts index e0c6668..4bb72e6 100644 --- a/src/runtime/server/plugin.ts +++ b/src/runtime/server/plugin.ts @@ -24,7 +24,9 @@ const proxyHandler = (config: ProxyParty) => { logger.success(`(${config.name || 'no name'})`, `Proxy path "${event.path}" accessed, forwarding to "${url}"`) } - return proxyRequest(event, url, config.proxyOptions) + const options = typeof config.proxyOptions === 'function' ? config.proxyOptions(event) : config.proxyOptions + + return proxyRequest(event, url, options) }) }