"use strict";

const fs = require("fs");
const path = require("path");

const nodeMajor = Number.parseInt(process.versions.node.split(".")[0], 10);
if (nodeMajor < 20) {
  throw new Error(`Encostay requires Node.js 20 or newer; found ${process.versions.node}.`);
}

const server = path.join(__dirname, ".next", "standalone", "server.js");
if (!fs.existsSync(server)) {
  throw new Error("Missing .next/standalone/server.js. Run `npm run build` before starting Passenger.");
}

process.env.NODE_ENV = process.env.NODE_ENV || "production";
process.env.PORT = process.env.PORT || "3000";
process.env.HOSTNAME = process.env.HOSTNAME || process.env.HOST || "0.0.0.0";

require(server);
