Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,42 @@ import { VERSION } from "./version.js";
const PORT = 1994;

async function main(): Promise<void> {

process.on("unhandledRejection", (reason) => {
console.error("Unhandled rejection:", reason);
});

const node = new Node(PORT);
const election = new Election(PORT, node);
await election.start();

// Graceful shutdown
const shutdown = () => {
console.error("Shutting down...");
let shuttingDown = false;
const shutdown = async (reason: string): Promise<void> => {
if (shuttingDown) return;
shuttingDown = true;
console.error(`Shutting down (${reason})...`);

const force = setTimeout(() => {
console.error("Shutdown timeout exceeded, forcing exit");
process.exit(0);
}, 5000);
force.unref();

election.stop();
node.stop();
process.exit(0);
Comment thread
dev-hann marked this conversation as resolved.
Resolved
};

process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
process.stdin.on("end", () => void shutdown("stdin end"));
process.stdin.on("close", () => void shutdown("stdin close"));

process.on("SIGINT", () => void shutdown("SIGINT"));
process.on("SIGTERM", () => void shutdown("SIGTERM"));
process.on("SIGHUP", () => void shutdown("SIGHUP"));

process.on("uncaughtException", (err) => {
process.on("uncaughtException", async (err) => {
console.error("Uncaught exception:", err);
shutdown();
await shutdown("uncaughtException");
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
process.on("unhandledRejection", (reason) => {
console.error("Unhandled rejection:", reason);
});

// Create MCP server (stdio transport)
const server = new McpServer({
name: "figma-bridge",
version: VERSION,
Expand Down