Files
GMW/services/backend/src/index.ts
T
asepharyana 0a6a9fd982
Deploy to VPS / deploy (push) Failing after 1m43s
feat: update dependencies and improve dashboard functionality
- Added new dependencies for Next.js and lucide-react in pnpm-workspace.yaml.
- Refactored DashboardPage component to improve readability and error handling.
- Enhanced Header component to display error status with an alert icon.
- Updated MobileTabBar and Sidebar components to use a centralized tabs definition.
- Improved ChannelsView in dashboard-panel to handle channel fetching more cleanly.
- Fixed ActiveSpeaker type to use camelCase for userId.
- Updated MessagesPanel to handle guildId checks more gracefully.
- Adjusted API calls in dashboard and messages to align with backend expectations.
- Refined type definitions across various interfaces for consistency and clarity.
2026-07-26 14:27:36 +07:00

78 lines
2.1 KiB
TypeScript

import type { Server } from "node:http";
import { createChildLogger } from "@bete/shared/logger";
import { startHttpServer } from "./http/server.js";
import { closeDatabase } from "./shared/database/index.js";
import { stopCommandBridge } from "./shared/redis/index.js";
import { stopRedisBridge as stopEventBridge } from "./ws/redis-bridge.js";
import { closeWebSocketServer } from "./ws/server.js";
const logger = createChildLogger("backend");
let httpServer: Server | undefined;
async function main() {
try {
logger.info("Starting Discord Moderation Backend Service");
httpServer = await startHttpServer();
logger.info("Backend service ready");
} catch (err) {
logger.error({ err }, "Failed to start backend service");
process.exit(1);
}
}
async function shutdown(signal: string) {
logger.info({ signal }, "Shutting down gracefully");
try {
// 1. Stop accepting new HTTP connections
if (httpServer) {
await new Promise<void>((resolve) => {
httpServer?.close(() => {
logger.info("HTTP server closed");
resolve();
});
});
}
// 2. Close WebSocket server
closeWebSocketServer();
// 3. Stop Redis bridges (event subscriptions + command channel)
await Promise.allSettled([
stopEventBridge().catch((err) =>
logger.warn({ err }, "Error stopping event bridge"),
),
stopCommandBridge().catch((err) =>
logger.warn({ err }, "Error stopping command bridge"),
),
]);
// 4. Close database pool
await closeDatabase().catch((err) =>
logger.warn({ err }, "Error closing database"),
);
logger.info("Graceful shutdown completed");
process.exit(0);
} catch (err) {
logger.error({ err }, "Error during graceful shutdown");
process.exit(1);
}
}
process.on("SIGINT", () => shutdown("SIGINT"));
process.on("SIGTERM", () => shutdown("SIGTERM"));
process.on("uncaughtException", (err) => {
logger.error({ err }, "Uncaught exception");
shutdown("uncaughtException");
});
process.on("unhandledRejection", (reason) => {
logger.error({ reason }, "Unhandled rejection");
shutdown("unhandledRejection");
});
main();