From 07a87b457103a14bf2265ff7ff0716d0ebe54fca Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 6 Jan 2024 18:32:53 +0100 Subject: [PATCH 1/3] Block more headers, where possible --- src/utils/headers.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/headers.ts b/src/utils/headers.ts index cc6a8a9..44a9cb6 100644 --- a/src/utils/headers.ts +++ b/src/utils/headers.ts @@ -12,6 +12,9 @@ const blacklistedHeaders = [ 'cf-ray', 'cf-visitor', 'cf-ew-via', + 'cdn-loop', + 'x-amzn-trace-id', + 'cf-ipcountry', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', From ad0ae4aaae0745a1c077d5f3e2826a0c5d650a6d Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 6 Jan 2024 18:37:40 +0100 Subject: [PATCH 2/3] Add version identifying on proxy --- nitro.config.ts | 4 ++++ package.json | 2 +- src/routes/index.ts | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nitro.config.ts b/nitro.config.ts index 29f6b56..ea52bd1 100644 --- a/nitro.config.ts +++ b/nitro.config.ts @@ -1,9 +1,13 @@ import { join } from "path"; +import pkg from "./package.json"; //https://nitro.unjs.io/config export default defineNitroConfig({ noPublicDir: true, srcDir: "./src", + runtimeConfig: { + version: pkg.version, + }, alias: { "@": join(__dirname, "src") } diff --git a/package.json b/package.json index 1f38a9d..23852a9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "simple-proxy", "private": true, - "version": "2.1.1", + "version": "2.1.2", "scripts": { "prepare": "nitropack prepare", "dev": "nitropack dev", diff --git a/src/routes/index.ts b/src/routes/index.ts index 3f7e059..c2860c5 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -21,7 +21,9 @@ export default defineEventHandler(async (event) => { event, status: 200, data: { - message: 'Proxy is working as expected', + message: `Proxy is working as expected (v${ + useRuntimeConfig(event).version + })`, }, }); From 5faca36cb4106276232578e6152be4c88081a627 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 6 Jan 2024 18:44:06 +0100 Subject: [PATCH 3/3] Add ability to do debug logging with REQ_DEBUG=true --- nitro.config.ts | 2 +- src/utils/proxy.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nitro.config.ts b/nitro.config.ts index ea52bd1..e7388dc 100644 --- a/nitro.config.ts +++ b/nitro.config.ts @@ -6,7 +6,7 @@ export default defineNitroConfig({ noPublicDir: true, srcDir: "./src", runtimeConfig: { - version: pkg.version, + version: pkg.version }, alias: { "@": join(__dirname, "src") diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts index 4a312fa..853d1aa 100644 --- a/src/utils/proxy.ts +++ b/src/utils/proxy.ts @@ -69,7 +69,15 @@ export async function specificProxyRequest( opts.fetchOptions?.headers, opts.headers, ); - (fetchHeaders.forEach as any)(console.log); + const headerObj = Object.fromEntries([...(fetchHeaders.entries as any)()]); + if (process.env.REQ_DEBUG === 'true') { + console.log({ + type: 'request', + method, + url: target, + headers: headerObj, + }); + } return sendProxy(event, target, { ...opts,