feat: metaset proxy com kernel discovery
- Adiciona função discoverMetasetEndpoint() que consulta o Kernel Registry - Prioridade 1: Registry global (mesmo processo) - Prioridade 2: HTTP request para porta 5001 - Fallback para configuração padrão se discovery falhar - setupMetasetProxy agora é async e usa endpoint descoberto
This commit is contained in:
parent
b296638888
commit
5f6e43f6e2
|
|
@ -5,8 +5,53 @@ const METASET_HOST = process.env.METASET_HOST || "metaset";
|
|||
const METASET_PORT = parseInt(process.env.METASET_PORT || "8100", 10);
|
||||
const METASET_TIMEOUT = 60000;
|
||||
|
||||
export function setupMetasetProxy(app: Express): void {
|
||||
const target = `http://${METASET_HOST}:${METASET_PORT}`;
|
||||
// Consulta o Kernel Registry para descobrir onde o Metaset está rodando
|
||||
async function discoverMetasetEndpoint(): Promise<string | null> {
|
||||
try {
|
||||
// PRIORIDADE 1: Registry global (mesmo processo)
|
||||
const globalRegistry = (global as any).arcadiaKernelRegistry;
|
||||
if (globalRegistry) {
|
||||
const services = globalRegistry.getServices();
|
||||
const metasetService = services.find((s: any) =>
|
||||
s.id === 'metaset' ||
|
||||
s.name?.toLowerCase().includes('metaset') ||
|
||||
s.displayName?.toLowerCase().includes('metaset')
|
||||
);
|
||||
|
||||
if (metasetService?.endpoint) {
|
||||
console.log(`[Metaset Proxy] Discovery via Kernel Registry: ${metasetService.endpoint}`);
|
||||
return metasetService.endpoint;
|
||||
}
|
||||
}
|
||||
|
||||
// PRIORIDADE 2: HTTP request para porta 5001
|
||||
const response = await fetch('http://127.0.0.1:5001/api/services');
|
||||
if (response.ok) {
|
||||
const services = await response.json();
|
||||
const metasetService = services.find((s: any) =>
|
||||
s.id === 'metaset' ||
|
||||
s.name?.toLowerCase().includes('metaset')
|
||||
);
|
||||
|
||||
if (metasetService?.endpoint) {
|
||||
console.log(`[Metaset Proxy] Discovery via HTTP: ${metasetService.endpoint}`);
|
||||
return metasetService.endpoint;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('[Metaset Proxy] Discovery falhou, usando fallback:', error);
|
||||
}
|
||||
|
||||
// FALLBACK: Configuração padrão
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function setupMetasetProxy(app: Express): Promise<void> {
|
||||
// Tenta descobrir endpoint via Kernel Discovery
|
||||
const discoveredEndpoint = await discoverMetasetEndpoint();
|
||||
const target = discoveredEndpoint || `http://${METASET_HOST}:${METASET_PORT}`;
|
||||
|
||||
console.log(`[Metaset Proxy] Configurando proxy -> ${target}`);
|
||||
|
||||
const metasetProxy = createProxyMiddleware({
|
||||
target,
|
||||
|
|
@ -35,5 +80,5 @@ export function setupMetasetProxy(app: Express): void {
|
|||
});
|
||||
|
||||
app.use("/metaset", metasetProxy);
|
||||
console.log(`[Metaset Proxy] Configurado -> /metaset/* => ${target}`);
|
||||
console.log(`[Metaset Proxy] Ativo em /metaset -> ${target}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ export async function registerRoutes(
|
|||
setupSupersetProxy(app);
|
||||
registerSupersetRoutes(app);
|
||||
|
||||
// MetaSet - BI alternativo (porta 8100)
|
||||
setupMetasetProxy(app);
|
||||
// MetaSet - BI alternativo (porta 8100) - com Kernel Discovery
|
||||
await setupMetasetProxy(app);
|
||||
|
||||
// ERPNext container proxy (ativo apenas em DOCKER_MODE ou ERPNEXT_PROXY_ENABLED=true)
|
||||
setupErpNextProxy(app);
|
||||
|
|
|
|||
Loading…
Reference in New Issue