From b567ba0c0647aa38a277b4f6e1cdb57f5e522689 Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Fri, 12 May 2023 11:11:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Try=20without=20lib=20for=20prox?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Try without lib for proxy * Tested and approved and using streams * Lint fix --- tdrive/backend/node/package.json | 1 - .../src/services/applications-api/index.ts | 37 +++++++++++-------- tdrive/backend/node/yarn.lock | 19 ---------- .../views/client/viewer/other/controls.tsx | 4 +- 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/tdrive/backend/node/package.json b/tdrive/backend/node/package.json index bd1ac673..5afbfdd7 100644 --- a/tdrive/backend/node/package.json +++ b/tdrive/backend/node/package.json @@ -161,7 +161,6 @@ "get-website-favicon": "^0.0.7", "html-metadata-parser": "^2.0.4", "html-to-text": "^8.2.1", - "http-proxy": "^1.18.1", "idtoken-verifier": "^2.2.3", "jsonwebtoken": "^8.5.1", "jwks-rsa": "^3.0.1", diff --git a/tdrive/backend/node/src/services/applications-api/index.ts b/tdrive/backend/node/src/services/applications-api/index.ts index 4b56ca73..07caa521 100644 --- a/tdrive/backend/node/src/services/applications-api/index.ts +++ b/tdrive/backend/node/src/services/applications-api/index.ts @@ -1,21 +1,11 @@ +import axios from "axios"; import config from "config"; -import httpProxy from "http-proxy"; +import _ from "lodash"; import { Prefix, TdriveService } from "../../core/platform/framework"; import WebServerAPI from "../../core/platform/services/webserver/provider"; import Application from "../applications/entities/application"; import web from "./web/index"; -const proxy = httpProxy.createProxyServer({}); -// https://github.com/http-party/node-http-proxy/issues/1471 -proxy.on("proxyReq", (proxyReq, req: any) => { - if (req.body && ["POST", "PATCH", "PUT"].includes(req.method)) { - const bodyData = JSON.stringify(req.body); - proxyReq.setHeader("content-type", "application/json"); - proxyReq.setHeader("content-length", Buffer.byteLength(bodyData)); - proxyReq.write(bodyData); - } -}); - @Prefix("/api") export default class ApplicationsApiService extends TdriveService { version = "1"; @@ -35,10 +25,25 @@ export default class ApplicationsApiService extends TdriveService { const prefix = app.external_prefix.replace(/(\/$|^\/)/gm, ""); if (domain && prefix) { try { - fastify.all("/" + prefix + "/*", (req, rep) => { - proxy.web(req.raw, rep.raw, { - target: domain, - }); + fastify.all("/" + prefix + "/*", async (req, rep) => { + console.log("Proxying", req.method, req.url, "to", domain); + try { + const response = await axios.request({ + url: domain + req.url, + method: req.method as any, + headers: _.omit(req.headers, "host", "content-length") as { + [key: string]: string; + }, + data: req.body as any, + responseType: "stream", + }); + rep.statusCode = response.status; + rep.send(response.data); + } catch (err) { + console.error(err); + rep.raw.statusCode = 500; + rep.raw.end(JSON.stringify({ error: err.message })); + } }); console.log("Listening at ", "/" + prefix + "/*"); } catch (e) { diff --git a/tdrive/backend/node/yarn.lock b/tdrive/backend/node/yarn.lock index 1dede87e..15f019f9 100644 --- a/tdrive/backend/node/yarn.lock +++ b/tdrive/backend/node/yarn.lock @@ -4531,11 +4531,6 @@ event-target-shim@^5.0.0: resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== -eventemitter3@^4.0.0: - version "4.0.7" - resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" - integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== - events@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" @@ -5034,11 +5029,6 @@ follow-redirects@1.5.10: dependencies: debug "=3.1.0" -follow-redirects@^1.0.0: - version "1.15.2" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" - integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== - follow-redirects@^1.14.0, follow-redirects@^1.14.4: version "1.15.1" resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz" @@ -5634,15 +5624,6 @@ http-proxy-agent@^4.0.1: agent-base "6" debug "4" -http-proxy@^1.18.1: - version "1.18.1" - resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549" - integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ== - dependencies: - eventemitter3 "^4.0.0" - follow-redirects "^1.0.0" - requires-port "^1.0.0" - http2-wrapper@^1.0.0-beta.5.2: version "1.0.3" resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.3.tgz#b8f55e0c1f25d4ebd08b3b0c2c079f9590800b3d" diff --git a/tdrive/frontend/src/app/views/client/viewer/other/controls.tsx b/tdrive/frontend/src/app/views/client/viewer/other/controls.tsx index 6e1b5363..0d13b6eb 100644 --- a/tdrive/frontend/src/app/views/client/viewer/other/controls.tsx +++ b/tdrive/frontend/src/app/views/client/viewer/other/controls.tsx @@ -29,7 +29,7 @@ export default () => { if (FeatureTogglesService.isActiveFeatureName(FeatureNames.EDIT_FILES)) { openFile( candidates[0].app, - status.details?.versions?.[0]?.id || '', + status.details?.versions?.[0]?.file_metadata?.external_id || '', status.details?.item.id || '', ); } else { @@ -63,7 +63,7 @@ export default () => { onClick: () => { openFile( editor.app, - status.details?.versions?.[0]?.id || '', + status.details?.versions?.[0]?.file_metadata?.external_id || '', status.details?.item.id || '', ); },