🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

h3-proxy

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3-proxy - npm Package Compare versions

Comparing version

to
1.13.0

7

lib/index.cjs.js

@@ -428,3 +428,3 @@ 'use strict';

if (finalOptions) {
const { target, pathRewrite, enableLogger, loggerOptions } = finalOptions;
const { target, pathRewrite, enableLogger, loggerOptions, proxyRequestMethod, } = finalOptions;
if (!target) {

@@ -443,4 +443,7 @@ throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);

const targetUrl = `${target}${rewritedPath}`;
logger && logger.success('proxy to target url:', targetUrl);
logger?.success('proxy to target url:', targetUrl);
const proxyRequestOptions = createProxyRequestOptions(event, finalOptions);
if (proxyRequestMethod) {
return proxyRequestMethod(event, targetUrl, proxyRequestOptions);
}
return h3.proxyRequest(event, targetUrl, proxyRequestOptions);

@@ -447,0 +450,0 @@ }

@@ -22,2 +22,8 @@ import { NodeIncomingMessage, H3Event, ProxyOptions, EventHandler } from 'h3';

type ProxyRequestMethod = (
event: H3Event,
target: string,
opts?: ProxyRequestOptions,
) => Promise<any>
type ConfigureProxyRequest = (event: H3Event) => ProxyRequestOptions

@@ -29,9 +35,11 @@

pathRewrite?: PathRewriterParams
// Configure options of proxyRequest which is h3's built-in util
/** Configure options of proxyRequest which is h3's built-in util */
configureProxyRequest?: ConfigureProxyRequest
// Whether to enable logger
/** customize proxyRequest method */
proxyRequestMethod?: ProxyRequestMethod
/** Whether to enable logger */
enableLogger?: boolean
// Configure the options of consola
/** Configure the options of consola */
loggerOptions?: ConsolaOptions
// true/false, Default: false - changes the origin of the host header to the target URL
/** true/false, Default: false - changes the origin of the host header to the target URL */
changeOrigin?: boolean

@@ -38,0 +46,0 @@ }

@@ -426,3 +426,3 @@ import isGlob from 'is-glob';

if (finalOptions) {
const { target, pathRewrite, enableLogger, loggerOptions } = finalOptions;
const { target, pathRewrite, enableLogger, loggerOptions, proxyRequestMethod, } = finalOptions;
if (!target) {

@@ -441,4 +441,7 @@ throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);

const targetUrl = `${target}${rewritedPath}`;
logger && logger.success('proxy to target url:', targetUrl);
logger?.success('proxy to target url:', targetUrl);
const proxyRequestOptions = createProxyRequestOptions(event, finalOptions);
if (proxyRequestMethod) {
return proxyRequestMethod(event, targetUrl, proxyRequestOptions);
}
return proxyRequest(event, targetUrl, proxyRequestOptions);

@@ -445,0 +448,0 @@ }

{
"name": "h3-proxy",
"version": "1.12.0",
"version": "1.13.0",
"description": "A proxy event handler for h3, using proxyRequest.",

@@ -26,3 +26,3 @@ "type": "module",

"test": "vitest run",
"test:coverage": "yarn test -- --reporter verbose --coverage",
"test:coverage": "pnpm test -- --reporter verbose --coverage",
"start": "node ./playground/main.js",

@@ -42,3 +42,6 @@ "start:multi-target-usage": "node ./playground/multi-target-usage.js"

"proxyRequest",
"middleware"
"middleware",
"nuxt",
"nuxt3",
"nuxt-proxy"
],

@@ -75,3 +78,3 @@ "author": {

"eslint-plugin-prettier": "^5.1.2",
"h3": "^1.9.0",
"h3": "^1.11.1",
"lodash": "^4.17.21",

@@ -78,0 +81,0 @@ "prettier": "^3.1.1",

@@ -161,3 +161,4 @@ <p align="center">

| [pathRewrite](https://github.com/yisibell/h3-proxy#pathRewrite) | `object/Function` | `false` | `undefined` | Rewrite target's url path. Object-keys will be used as RegExp to match paths. |
| [configureProxyRequest](https://github.com/yisibell/h3-proxy#configureProxyRequest) | `Function` | `false` | `undefined` | Configure options of `proxyRequest`. More details see <a href="https://github.com/unjs/h3">built-in util proxyRequest of h3</a> |
| [configureProxyRequest](https://github.com/yisibell/h3-proxy#configureProxyRequest) | `Function` | `false` | `undefined` | Configure options of `proxyRequest`. More details see [built-in util proxyRequest of h3](https://github.com/unjs/h3) |
| `proxyRequestMethod` <br /> Added in **v1.13.0** | `Function` | `false` | `undefined` | Customize `proxyRequest` of **h3** method. |
| `enableLogger` | `boolean` | `false` | `true` | Whether to enable logger which is created by **consola**. |

@@ -164,0 +165,0 @@ | `loggerOptions` | `ConsolaOptions` | `false` | `{}` | Configure the options of [consola](https://github.com/unjs/consola). |