Move to http-proxy
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import config from "config";
|
||||
import httpProxy from "http-proxy";
|
||||
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";
|
||||
import httpProxy from "@fastify/http-proxy";
|
||||
|
||||
var proxy = httpProxy.createProxyServer({});
|
||||
|
||||
@Prefix("/api")
|
||||
export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
@@ -23,11 +25,17 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
const domain = app.internal_domain.replace(/(\/$|^\/)/gm, "");
|
||||
const prefix = app.external_prefix.replace(/(\/$|^\/)/gm, "");
|
||||
if (domain && prefix) {
|
||||
console.log("Listening at ", "/" + prefix + "/*");
|
||||
fastify.register(httpProxy, {
|
||||
upstream: domain + "/" + prefix,
|
||||
prefix: "/" + prefix,
|
||||
});
|
||||
try {
|
||||
fastify.all("/" + prefix + "/*", (req, rep) => {
|
||||
proxy.web(req.raw, rep.raw, {
|
||||
target: domain,
|
||||
});
|
||||
});
|
||||
console.log("Listening at ", "/" + prefix + "/*");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
console.log("Can't listen to ", "/" + prefix + "/*");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user