/* eslint-disable @typescript-eslint/no-require-imports */
const http = require("node:http");
const next = require("next");

const port = Number(process.env.PORT || 3000);
const hostname = process.env.HOST || "0.0.0.0";
const app = next({ dev: false, hostname, port });
const handle = app.getRequestHandler();

app
  .prepare()
  .then(() => {
    http.createServer((request, response) => handle(request, response)).listen(port, hostname, () => {
      console.log(`Kafala is listening on ${hostname}:${port}`);
    });
  })
  .catch((error) => {
    console.error("Unable to start Kafala:", error instanceof Error ? error.message : "unknown error");
    process.exit(1);
  });
