From 6b7c88fd891714ad9b0444376fa5a3df59391764 Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Wed, 10 May 2023 17:21:56 +0200 Subject: [PATCH] Use another reverse proxy for plugins --- tdrive/backend/node/package.json | 2 +- .../src/services/applications-api/index.ts | 17 ++-- tdrive/backend/node/yarn.lock | 81 +++++++++++++++---- 3 files changed, 72 insertions(+), 28 deletions(-) diff --git a/tdrive/backend/node/package.json b/tdrive/backend/node/package.json index 2a448719..70573b50 100644 --- a/tdrive/backend/node/package.json +++ b/tdrive/backend/node/package.json @@ -118,6 +118,7 @@ "@elastic/elasticsearch": "7", "@fastify/caching": "^7.0.0", "@fastify/formbody": "^6.0.0", + "@fastify/http-proxy": "^9.1.0", "@fastify/static": "^5.0.1", "@ffprobe-installer/ffprobe": "^1.4.1", "@sentry/node": "^6.19.7", @@ -140,7 +141,6 @@ "deep-object-diff": "^1.1.0", "emoji-name-map": "^1.2.9", "eta": "^1.12.3", - "fast-proxy": "^2.1.0", "fastify": "^3.29.4", "fastify-cors": "^4.1.0", "fastify-formbody": "^5.0.0", diff --git a/tdrive/backend/node/src/services/applications-api/index.ts b/tdrive/backend/node/src/services/applications-api/index.ts index 8fa658e7..57fffa24 100644 --- a/tdrive/backend/node/src/services/applications-api/index.ts +++ b/tdrive/backend/node/src/services/applications-api/index.ts @@ -1,5 +1,5 @@ import config from "config"; -import FastProxy from "fast-proxy"; +import FastProxy from "@fastify/http-proxy"; import { Prefix, TdriveService } from "../../core/platform/framework"; import WebServerAPI from "../../core/platform/services/webserver/provider"; import Application from "../applications/entities/application"; @@ -20,16 +20,13 @@ export default class ApplicationsApiService extends TdriveService { //Redirect requests from /plugins/* to the plugin server (if installed) const apps = config.get("applications.plugins") || []; for (const app of apps) { - const domain = app.internal_domain; - const prefix = app.external_prefix; + const domain = app.internal_domain.replace(/(\/$|^\/)/gm, ""); + const prefix = app.external_prefix.replace(/(\/$|^\/)/gm, ""); if (domain && prefix) { - const { proxy, close } = FastProxy({ - base: domain, - }); - console.log("Listening at ", "/" + prefix.replace(/(\/$|^\/)/gm, "") + "/*"); - fastify.addHook("onClose", close); - fastify.all("/" + prefix.replace(/(\/$|^\/)/gm, "") + "/*", (req, rep) => { - proxy(req.raw, rep.raw, req.url, {}); + console.log("Listening at ", "/" + prefix + "/*"); + fastify.register(FastProxy, { + upstream: domain + "/" + prefix, + prefix: "/" + prefix, }); } } diff --git a/tdrive/backend/node/yarn.lock b/tdrive/backend/node/yarn.lock index bc3a4165..3c937233 100644 --- a/tdrive/backend/node/yarn.lock +++ b/tdrive/backend/node/yarn.lock @@ -1105,6 +1105,11 @@ resolved "https://registry.npmjs.org/@fastify/error/-/error-2.0.0.tgz" integrity sha512-wI3fpfDT0t7p8E6dA2eTECzzOd+bZsZCJ2Hcv+Onn2b7ZwK3RwD27uW2QDaMtQhAfWQQP+WNK7nKf0twLsBf9w== +"@fastify/error@^3.0.0": + version "3.2.0" + resolved "https://registry.yarnpkg.com/@fastify/error/-/error-3.2.0.tgz#9010e0acfe07965f5fc7d2b367f58f042d0f4106" + integrity sha512-KAfcLa+CnknwVi5fWogrLXgidLic+GXnLjijXdpl8pvkvbXU5BGa37iZO9FGvsh9ZL4y+oFi5cbHBm5UOG+dmQ== + "@fastify/formbody@^6.0.0": version "6.0.1" resolved "https://registry.npmjs.org/@fastify/formbody/-/formbody-6.0.1.tgz" @@ -1112,6 +1117,28 @@ dependencies: fastify-plugin "^3.0.0" +"@fastify/http-proxy@^9.1.0": + version "9.1.0" + resolved "https://registry.yarnpkg.com/@fastify/http-proxy/-/http-proxy-9.1.0.tgz#594849d9778e342da92c919c4cc8b8ac9fe5eeb3" + integrity sha512-vgHCTDKOqLB437zQJiLWFFnsrYfFZ6Lfwu/xXQoKqRUKIPDt+xG6LBRtf8s5MNqfFVoTE7kw1U/0qdRGDsMp4Q== + dependencies: + "@fastify/reply-from" "^9.0.0" + fastify-plugin "^4.5.0" + ws "^8.4.2" + +"@fastify/reply-from@^9.0.0": + version "9.0.1" + resolved "https://registry.yarnpkg.com/@fastify/reply-from/-/reply-from-9.0.1.tgz#aa918519c2f9c1a7399ddfa6b6437303af51d2a7" + integrity sha512-q9vFNUiXZTY1x8omDPe59os2MYq+3y7KgO/kZoXpZlnud+45Nd8Ot/svEvrUATzjkizIggfS4K8LR9zXDyZZKg== + dependencies: + "@fastify/error" "^3.0.0" + end-of-stream "^1.4.4" + fast-querystring "^1.0.0" + fastify-plugin "^4.0.0" + pump "^3.0.0" + tiny-lru "^10.0.0" + undici "^5.19.1" + "@fastify/static@^5.0.1": version "5.0.2" resolved "https://registry.npmjs.org/@fastify/static/-/static-5.0.2.tgz" @@ -3075,6 +3102,13 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" +busboy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" + integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== + dependencies: + streamsearch "^1.1.0" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -4696,16 +4730,12 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: resolved "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== -fast-proxy@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/fast-proxy/-/fast-proxy-2.1.0.tgz#f4544e1db5fa72cb584a6a28497717cc88c561a6" - integrity sha512-ihCPWH8j4pfSIULx6evT39RzZjCkGScCVn2BRyJElDu3v96NCWjPJPX8Olnzxv30mMQUEEijonTKroqCVpXjUQ== +fast-querystring@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/fast-querystring/-/fast-querystring-1.1.1.tgz#f4c56ef56b1a954880cfd8c01b83f9e1a3d3fda2" + integrity sha512-qR2r+e3HvhEFmpdHMv//U8FnFlnYjaC6QKDuaXALDkw2kvHO8WDjxH+f/rHGR4Me4pnk8p9JAkRNTjYHAKRn2Q== dependencies: - end-of-stream "^1.4.4" - pump "^3.0.0" - semver "^7.3.5" - tiny-lru "^7.0.6" - undici "^3.3.6" + fast-decode-uri-component "^1.0.1" fast-redact@^3.0.0: version "3.1.1" @@ -4804,6 +4834,11 @@ fastify-plugin@^3.0.0, fastify-plugin@^3.0.1: resolved "https://registry.yarnpkg.com/fastify-plugin/-/fastify-plugin-3.0.1.tgz#79e84c29f401020f38b524f59f2402103fd21ed2" integrity sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA== +fastify-plugin@^4.0.0, fastify-plugin@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/fastify-plugin/-/fastify-plugin-4.5.0.tgz#8b853923a0bba6ab6921bb8f35b81224e6988d91" + integrity sha512-79ak0JxddO0utAXAQ5ccKhvs6vX2MGyHHMMsmZkBANrq3hXc1CHzvNPHOcvTsVMEPl5I+NT+RO4YKMGehOfSIg== + fastify-sensible@=3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/fastify-sensible/-/fastify-sensible-3.0.1.tgz#9577ecb1c499b72b80ffabf6fae3b2d2b26f2dbc" @@ -9313,6 +9348,11 @@ stream-wormhole@^1.1.0: resolved "https://registry.yarnpkg.com/stream-wormhole/-/stream-wormhole-1.1.0.tgz#300aff46ced553cfec642a05251885417693c33d" integrity sha512-gHFfL3px0Kctd6Po0M8TzEvt3De/xu6cnRrjlfYNhwbhLPLwigI2t1nc6jrzNuaYg5C4YF78PPFuQPzRiqn9ew== +streamsearch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" + integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== + string-argv@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.1.2.tgz#c5b7bc03fb2b11983ba3a72333dd0559e77e4738" @@ -9576,10 +9616,10 @@ through@2, through@~2.3, through@~2.3.1: resolved "https://registry.npmjs.org/through/-/through-2.3.8.tgz" integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== -tiny-lru@^7.0.6: - version "7.0.6" - resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-7.0.6.tgz#b0c3cdede1e5882aa2d1ae21cb2ceccf2a331f24" - integrity sha512-zNYO0Kvgn5rXzWpL0y3RS09sMK67eGaQj9805jlK9G6pSadfriTczzLHFXa/xcW4mIRfmlB9HyQ/+SgL0V1uow== +tiny-lru@^10.0.0: + version "10.4.1" + resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-10.4.1.tgz#dec67a62115a4cb31d2065b8116d010daac362fe" + integrity sha512-buLIzw7ppqymuO3pt10jHk/6QMeZLbidihMQU+N6sogF6EnBzG0qtDWIHuhw1x3dyNgVL/KTGIZsTK81+yCzLg== tiny-lru@^8.0.1: version "8.0.2" @@ -9858,10 +9898,12 @@ undefsafe@^2.0.2: resolved "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== -undici@^3.3.6: - version "3.3.6" - resolved "https://registry.yarnpkg.com/undici/-/undici-3.3.6.tgz#06d3b97b7eeff46bce6f8a71079c09f64dd59dc1" - integrity sha512-/j3YTZ5AobMB4ZrTY72mzM54uFUX32v0R/JRW9G2vOyF1uSKYAx+WT8dMsAcRS13TOFISv094TxIyWYk+WEPsA== +undici@^5.19.1: + version "5.22.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.22.0.tgz#5e205d82a5aecc003fc4388ccd3d2c6e8674a0ad" + integrity sha512-fR9RXCc+6Dxav4P9VV/sp5w3eFiSdOjJYsbtWfd4s5L5C4ogyuVpdKIVHeW0vV1MloM65/f7W45nR9ZxwVdyiA== + dependencies: + busboy "^1.6.0" unfetch@^4.2.0: version "4.2.0" @@ -10258,6 +10300,11 @@ ws@^7.4.2, ws@^7.4.6: resolved "https://registry.npmjs.org/ws/-/ws-7.5.8.tgz" integrity sha512-ri1Id1WinAX5Jqn9HejiGb8crfRio0Qgu8+MtL36rlTA6RLsMdWt1Az/19A2Qij6uSHUMphEFaTKa4WG+UNHNw== +ws@^8.4.2: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== + ws@~7.4.2: version "7.4.6" resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"