Comparing version
@@ -353,6 +353,7 @@ 'use strict'; | ||
const createProxyEventHandler = (options) => { | ||
const { target, pathFilter, pathRewrite, proxyRequestOptions } = options; | ||
const { target, pathFilter, pathRewrite, configureProxyRequest } = options; | ||
return (event) => { | ||
const { req } = event.node; | ||
const path = url.parse(req.url || '').pathname || ''; | ||
const proxyRequestOptions = typeof configureProxyRequest === 'function' ? configureProxyRequest(event) : undefined; | ||
if (isTargetFilterPath(path, { pathFilter, req })) { | ||
@@ -359,0 +360,0 @@ const pathRewriter = createPathRewriter(pathRewrite); |
@@ -1,2 +0,2 @@ | ||
import { EventHandler, ProxyOptions } from 'h3'; | ||
import { EventHandler, H3Event, ProxyOptions } from 'h3'; | ||
import { IncomingMessage } from 'http'; | ||
@@ -20,2 +20,4 @@ | ||
type ConfigureProxyRequest = (event: H3Event) => ProxyOptions | ||
interface CreateProxyEventHandlerOptions { | ||
@@ -25,3 +27,3 @@ target: string | ||
pathRewrite?: PathRewriterParams | ||
proxyRequestOptions?: ProxyOptions | ||
configureProxyRequest?: ConfigureProxyRequest | ||
} | ||
@@ -28,0 +30,0 @@ |
@@ -351,6 +351,7 @@ import isGlob from 'is-glob'; | ||
const createProxyEventHandler = (options) => { | ||
const { target, pathFilter, pathRewrite, proxyRequestOptions } = options; | ||
const { target, pathFilter, pathRewrite, configureProxyRequest } = options; | ||
return (event) => { | ||
const { req } = event.node; | ||
const path = url.parse(req.url || '').pathname || ''; | ||
const proxyRequestOptions = typeof configureProxyRequest === 'function' ? configureProxyRequest(event) : undefined; | ||
if (isTargetFilterPath(path, { pathFilter, req })) { | ||
@@ -357,0 +358,0 @@ const pathRewriter = createPathRewriter(pathRewrite); |
{ | ||
"name": "h3-proxy", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "A proxy event handler for h3, using proxyRequest.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -75,2 +75,3 @@ <p align="center"> | ||
| `pathRewrite` | `object/Function` | `false` | Rewrite target's url path. Object-keys will be used as RegExp to match paths. | | ||
| `configureProxyRequest` | `Function` | `false` | Configure options of `proxyRequest`. More details see <a href="https://github.com/unjs/h3"></a> | | ||
@@ -77,0 +78,0 @@ |
26704
1.87%657
0.46%80
1.27%