baraqex 1.0.67 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -633,22 +633,30 @@ var init_api_router = __esm({
633
633
  ApiRouter = class {
634
634
  constructor(apiDir, auth = null) {
635
635
  this.router = null;
636
+ this.initialized = false;
636
637
  this.apiDir = path.resolve(process.cwd(), apiDir);
637
638
  this.auth = auth;
638
- this.initializeRouter();
639
639
  }
640
- async initializeRouter() {
640
+ async initialize() {
641
+ if (this.initialized && this.router)
642
+ return;
641
643
  try {
642
644
  const express = await import("express");
643
645
  this.router = express.default.Router();
644
646
  this.setupRoutes();
647
+ this.initialized = true;
648
+ console.log("\u2705 API Router initialized successfully");
645
649
  } catch (error) {
650
+ console.error("\u274C Failed to initialize API Router:", error);
646
651
  if (error.code === "MODULE_NOT_FOUND") {
647
652
  throw new Error("Express not installed. Run: npm install express @types/express");
648
653
  }
649
654
  throw error;
650
655
  }
651
656
  }
657
+ isInitialized() {
658
+ return this.initialized && this.router !== null;
659
+ }
652
660
  setupRoutes() {
653
661
  if (!fs.existsSync(this.apiDir)) {
654
662
  console.log(`API directory not found: ${this.apiDir}`);
@@ -1440,8 +1448,14 @@ var init_server = __esm({
1440
1448
  throw error;
1441
1449
  }
1442
1450
  }
1443
- setupApiRoutes() {
1451
+ async setupApiRoutes() {
1444
1452
  const apiRouter = new ApiRouter(this.config.apiDir, this.auth);
1453
+ await apiRouter.initialize();
1454
+ if (!apiRouter.isInitialized() || !apiRouter.router) {
1455
+ console.warn("\u26A0\uFE0F API router not initialized properly - skipping API routes");
1456
+ return;
1457
+ }
1458
+ console.log("\u2705 Setting up API routes...");
1445
1459
  this.app.use("/api", requestLogger, apiRouter.router);
1446
1460
  this.app.get("/api-docs", (req, res) => {
1447
1461
  const apiDocs = this.generateApiDocs();