fosrl.pangolin/server/index.ts

71 lines
1.9 KiB
TypeScript
Raw Normal View History

#! /usr/bin/env node
2025-04-06 16:06:50 -04:00
import "./extendZod.ts";
import { runSetupFunctions } from "./setup";
2024-12-07 22:07:13 -05:00
import { createApiServer } from "./apiServer";
import { createNextServer } from "./nextServer";
import { createInternalServer } from "./internalServer";
2025-06-04 12:02:07 -04:00
import { ApiKey, ApiKeyOrg, Session, User, UserOrg } from "@server/db";
import { createIntegrationApiServer } from "./integrationApiServer";
2025-08-14 11:11:01 -07:00
import { createHybridClientServer } from "./hybridServer";
2025-05-13 11:09:38 -04:00
import config from "@server/lib/config";
2025-08-14 17:06:07 -07:00
import { setHostMeta } from "@server/lib/hostMeta";
import { initTelemetryClient } from "./lib/telemetry.js";
2025-08-17 21:58:27 -07:00
import { TraefikConfigManager } from "./lib/traefikConfig.js";
2024-12-07 22:07:13 -05:00
async function startServers() {
2025-08-14 17:06:07 -07:00
await setHostMeta();
2025-06-25 12:18:29 -04:00
await config.initServer();
2024-12-22 12:33:49 -05:00
await runSetupFunctions();
2024-12-07 22:07:13 -05:00
2025-08-14 17:06:07 -07:00
initTelemetryClient();
// Start all servers
const apiServer = createApiServer();
const internalServer = createInternalServer();
2025-08-12 14:30:23 -07:00
let hybridClientServer;
2025-08-14 11:58:08 -07:00
let nextServer;
2025-08-12 16:47:59 -07:00
if (config.isHybridMode()) {
2025-08-14 11:58:08 -07:00
hybridClientServer = await createHybridClientServer();
} else {
nextServer = await createNextServer();
2025-08-17 21:58:27 -07:00
if (config.getRawConfig().traefik.file_mode) {
const monitor = new TraefikConfigManager();
await monitor.start();
}
2025-08-12 14:30:23 -07:00
}
let integrationServer;
2025-05-13 11:09:38 -04:00
if (config.getRawConfig().flags?.enable_integration_api) {
integrationServer = createIntegrationApiServer();
}
return {
apiServer,
nextServer,
internalServer,
2025-08-12 14:30:23 -07:00
integrationServer,
hybridClientServer
};
2024-12-07 22:07:13 -05:00
}
2024-10-03 20:55:54 -04:00
2024-12-07 22:07:13 -05:00
// Types
2024-10-26 17:19:10 -04:00
declare global {
namespace Express {
interface Request {
apiKey?: ApiKey;
user?: User;
session: Session;
userOrg?: UserOrg;
apiKeyOrg?: ApiKeyOrg;
userOrgRoleId?: number;
userOrgId?: string;
userOrgIds?: string[];
}
2024-10-03 20:55:54 -04:00
}
2024-10-26 17:19:10 -04:00
}
2024-12-07 22:07:13 -05:00
startServers().catch(console.error);