import { getConfig } from "./config";
import { ensureSeededDatabase } from "./database";
import { createApp } from "./app";

export function startServer(port = getConfig().port, dbPath = getConfig().dbPath) {
  const db = ensureSeededDatabase(dbPath);
  const app = createApp(db);

  return app.listen(port, () => {
    console.info("mock-task-api:listening", {
      port,
      dbPath,
    });
  });
}

if (import.meta.main) {
  startServer();
}
