Bootstrap static json applications definition

This commit is contained in:
Romaric Mourgues
2023-04-14 10:07:34 +02:00
parent 1d83a583dc
commit 18e10b6a8b
19 changed files with 620 additions and 704 deletions
@@ -0,0 +1,42 @@
import { Prefix, TdriveService } from "../../core/platform/framework";
import WebServerAPI from "../../core/platform/services/webserver/provider";
import web from "./web/index";
import FastProxy from "fast-proxy";
import globalResolver from "../global-resolver";
@Prefix("/api")
export default class ApplicationsApiService extends TdriveService<undefined> {
version = "1";
name = "applicationsapi";
public async doInit(): Promise<this> {
const fastify = this.context.getProvider<WebServerAPI>("webserver").getServer();
fastify.register((instance, _opts, next) => {
web(instance, { prefix: this.prefix });
next();
});
//Redirect requests from /plugins/* to the plugin server (if installed)
const apps = await globalResolver.services.applications.marketplaceApps.list(null);
for (const app of apps) {
const domain = app.internal_domain;
const prefix = app.external_prefix;
if (domain && prefix) {
const { proxy, close } = FastProxy({
base: domain,
});
fastify.addHook("onClose", close);
fastify.all("/" + prefix.replace(/(\/$|^\/)/, "") + "/*", (req, rep) => {
proxy(req.raw, rep.raw, req.url, {});
});
}
}
return this;
}
// TODO: remove
api(): undefined {
return undefined;
}
}