From 5916c92b6a3db28ba89e02a730ba944ec92cd8f2 Mon Sep 17 00:00:00 2001 From: andidev308 Date: Sun, 4 Jun 2023 02:26:20 +0700 Subject: [PATCH 1/2] - fix object url in request - add return on reply --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8910b16..f410766 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ const fp = require('fastify-plugin') const proxy = route => async (request, reply) => { try { - request.req.url = request.req.url.replace(route.prefix, route.prefixRewrite) + request.url = request.url.replace(route.prefix, route.prefixRewrite) const shouldAbortProxy = await route.hooks.onRequest(request, reply) if (!shouldAbortProxy) { - reply.from(route.target + request.req.url, Object.assign({}, route.hooks)) + return reply.from(route.target + request.url, Object.assign({}, route.hooks)) } } catch (err) { - reply.send(err) + return reply.send(err) } } From 8819cfa08e69b2653b32eff594658d0be2700fd5 Mon Sep 17 00:00:00 2001 From: andidev308 Date: Sun, 4 Jun 2023 02:48:25 +0700 Subject: [PATCH 2/2] - fix url replace not working --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f410766..4a4ff37 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,11 @@ const fp = require('fastify-plugin') const proxy = route => async (request, reply) => { try { - request.url = request.url.replace(route.prefix, route.prefixRewrite) + const url = request.url.replace(route.prefix, route.prefixRewrite) + request.url = url const shouldAbortProxy = await route.hooks.onRequest(request, reply) if (!shouldAbortProxy) { - return reply.from(route.target + request.url, Object.assign({}, route.hooks)) + return reply.from(route.target + url, Object.assign({}, route.hooks)) } } catch (err) { return reply.send(err)