🛠 Try without lib for proxy
* Try without lib for proxy * Tested and approved and using streams * Lint fix
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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<undefined> {
|
||||
version = "1";
|
||||
@@ -35,10 +25,25 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 || '',
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user