Skip to content

Commit

Permalink
feat: enhance proxyOptions with function-based
Browse files Browse the repository at this point in the history
  • Loading branch information
radyakaze committed Oct 7, 2024
1 parent b00a65b commit 1a9c9f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/runtime/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 1a9c9f1

Please sign in to comment.