From f71176a764f3ea9e178519fd6093478649d740e1 Mon Sep 17 00:00:00 2001 From: Eliphaz BOUYE Date: Fri, 24 Feb 2023 16:32:53 +0000 Subject: [PATCH 1/4] added fastify-plugin --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 9c95c27..6b1a904 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ }, "dependencies": { "@fastify/reply-from": "^8.0.0", + "fastify-plugin": "^4.5.0", "ws": "^8.4.2" }, "tsd": { From 9787955ea7e4121704bc32c72265985bfe798451 Mon Sep 17 00:00:00 2001 From: Eliphaz BOUYE Date: Mon, 27 Feb 2023 13:46:16 +0000 Subject: [PATCH 2/4] change default exportations to fasti-plugin --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index d0f24a6..e86148d 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const From = require('@fastify/reply-from') const WebSocket = require('ws') const { convertUrlToWebSocket } = require('./utils') +const fp = require('fastify-plugin') const httpMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] const urlPattern = /^https?:\/\// @@ -261,11 +262,15 @@ async function fastifyHttpProxy (fastify, opts) { } } -fastifyHttpProxy[Symbol.for('plugin-meta')] = { +module.exports = fp(fastifyHttpProxy, { fastify: '4.x', name: '@fastify/http-proxy' -} - -module.exports = fastifyHttpProxy -module.exports.default = fastifyHttpProxy -module.exports.fastifyHttpProxy = fastifyHttpProxy +}) +module.exports.default = fp(fastifyHttpProxy, { + fastify: '4.x', + name: '@fastify/http-proxy' +}) +module.exports.fastifyHttpProxy = fp(fastifyHttpProxy, { + fastify: '4.x', + name: '@fastify/http-proxy' +}) From 7ec19dcd6d40eb690cc0cd5b9a2d2185207aa831 Mon Sep 17 00:00:00 2001 From: Eliphaz BOUYE Date: Mon, 27 Feb 2023 14:56:41 +0000 Subject: [PATCH 3/4] use same style as the other official plugins --- index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index e86148d..ff403d0 100644 --- a/index.js +++ b/index.js @@ -266,11 +266,5 @@ module.exports = fp(fastifyHttpProxy, { fastify: '4.x', name: '@fastify/http-proxy' }) -module.exports.default = fp(fastifyHttpProxy, { - fastify: '4.x', - name: '@fastify/http-proxy' -}) -module.exports.fastifyHttpProxy = fp(fastifyHttpProxy, { - fastify: '4.x', - name: '@fastify/http-proxy' -}) +module.exports.default = fastifyHttpProxy +module.exports.fastifyHttpProxy = fastifyHttpProxy From 743a26c7479ab12f653762de1c46b291ed434f6b Mon Sep 17 00:00:00 2001 From: Eliphaz BOUYE Date: Mon, 27 Feb 2023 17:32:51 +0000 Subject: [PATCH 4/4] fix: I have fixed the tests suite who fails by add encapsulate to true on the fastify-plugin --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ff403d0..93400fe 100644 --- a/index.js +++ b/index.js @@ -264,7 +264,8 @@ async function fastifyHttpProxy (fastify, opts) { module.exports = fp(fastifyHttpProxy, { fastify: '4.x', - name: '@fastify/http-proxy' + name: '@fastify/http-proxy', + encapsulate: true }) module.exports.default = fastifyHttpProxy module.exports.fastifyHttpProxy = fastifyHttpProxy